繁体   English   中英

选择不使用角度2绑定动态更新的选项

[英]select options not updating dynamically with angular 2 bindings

我无法获得select选项以使用Angular2绑定动态更新。 如何动态select的内容?

请解释我的问题。 请注意, select选项永远不会更新到我设置的新阵列。

因为当你reassinging 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];    
}

Demo Plunkr

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM