单击angular 4中不处理选项标记的事件 const供应商=[ {姓名:'测试',年龄:123}, {姓名:'tes34t',年龄:12233} ] {{l}
我的点击在IE中不起作用,它在chrome中起作用。如何使其在IE中工作?单击angular 4中不处理选项标记的事件 const供应商=[ {姓名:'测试',年龄:123}, {姓名:'tes34t',年龄:12233} ] {{l},angular,internet-explorer,select,Angular,Internet Explorer,Select,我的点击在IE中不起作用,它在chrome中起作用。如何使其在IE中工作?onclick不是选项的有效事件标记()。您应该使用select标记上的onchange事件来获取值更改时的事件。例如: {{l} 不要选择选项上的(单击),而是选择上的(更改)。我建议这样做,因为它的性能更高,只有在选项更改时才会触发。这就是我们在这里要找的 在这里,尝试一下: const vendors = [ {name: 'test', age: 123}, {name: 'tes34t', age:
onclick
不是选项的有效事件标记()。您应该使用select
标记上的onchange
事件来获取值更改时的事件。例如:
{{l}
不要选择选项上的(单击)
,而是选择上的(更改)
。我建议这样做,因为它的性能更高,只有在选项更改时才会触发。这就是我们在这里要找的
在这里,尝试一下:
const vendors = [
{name: 'test', age: 123},
{name: 'tes34t', age: 12233}
]
<select>
<option *ngFor="let l of vendors" (click)="findSso(l)">{{ l }} </option>
</select>
这是给你的裁判的一封信
更新
如果希望传递完整对象,可以执行以下操作:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
vendors = [
{ name: 'test', age: 123 },
{ name: 'tes34t', age: 12233 }
];
findSso(selectedVendor) {
console.log('Got the selectedVendor as : ', selectedVendor);
// DO the needful here.
}
}
代码已出现在示例StackBlitz中。而不是(单击)
请使用更改事件。和[(ngModel)]
可用于通过ngModelChange
事件检测更改
对于
tag[ngValue]
指令可以采用字符串
或对象
,通过ngModel
我们可以跟踪更改事件
findSso(selectedVendor) {
console.log('Got the selectedVendor as : ', JSON.parse(selectedVendor));
}
选择供应商
{{vendor.name}
为便于参考,添加了代码。为什么不使用