angular5 - (更改)不适用于角度 5 中的 select2
问题描述
(change) 指令与角度 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();
});
解决方案
jquery
使用生命周期钩子执行更改事件:
ngOnInit() {
$('.select2Select').on('select2:select', function (e) {
console.log("Hi");
});
}
推荐阅读
- c# - C# PSExec 从 StreamReader 解析执行多个路径
- javascript - 将变量声明为函数并在一个语句中具有属性
- python - 三角形*数字*图案
- javascript - 删除调用 onclick 的元素
- javascript - ValidateUsername 是只读的 | 带有 Jest/Enzyme 的 TS
- javascript - React + Typescript 对象道具到组件错误
- ruby - Prawn PDF中的左右拆分
- sql - 按 ID 选择最小 Seq Num
- python - 如何返回数据结构中的所有项目?
- amazon-web-services - “你想让你的电脑被这个网络上的其他电脑和设备发现吗?”的含义是什么?在 AWS EC2 上?