【问题标题】:(change) not working with select2 in angular 5(更改)不适用于角度 5 中的 select2
【发布时间】:2018-11-13 17:13:25
【问题描述】:

(change) 指令在 angular 5 中与普通 select html 标记一起工作正常。但是如果我实现 select2 插件,那么 (change) 将不起作用。

这是我的 html 文件

<select class="select2Select" [(ngModel)]="productSearchItem" (ngModelChange)="test()">
  <option value="">Search entire store here...</option>
  <option *ngFor="let product of products" value="{{ product.pid }}">{{ product.name }}</option>
</select>

这个函数什么都不做,只是在打字稿中安慰一些东西

test(){
    console.log("Hi");
}

脚本:

$(document).ready(function() {
  $('.select2Select').select2();
});

【问题讨论】:

    标签: angular5 jquery-select2


    【解决方案1】:

    在生命周期钩子中使用jquery 执行更改事件:

    ngOnInit() {
      $('.select2Select').on('select2:select', function (e) {
        console.log("Hi");
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 2023-04-06
      • 2018-07-09
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2021-10-27
      相关资源
      最近更新 更多