我无法获取 select
选项来使用 Angular2
绑定(bind)动态更新。如何动态更新 select
的内容?
Plnkr explaining my issue.请注意,select
选项永远不会更新为我设置的新数组。
最佳答案
因为当您重新设置 options
值时,您必须在 options
之前使用 this
指向当前的 options
>.
handleChange(event) {
console.log(event.target.value);
//this to indicate options from current class
this.options = [{id: 0, name:"First"}, {id: 1, name:"Second"}, {id: 2, name:"Third"}];
this.selected1 = this.options.filter((option) => {
return option.id == event.target.value;
})[0];
}
关于javascript - 选择不使用 Angular 2 绑定(bind)动态更新的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39312914/