Angular 2 Beta –选择不起作用(Chrome中除外)

问题描述:

我只是对选择元素有一个简单的问题.我花了很多时间调试我的代码,因为select元素没有接受更改.但是后来我发现了一些有趣的东西.他们在其页面angualr.io上有表单示例: https://angular. io/resources/live-examples/forms/ts/plnkr.html .如果您在非Chrome的浏览器(如Firefox,Edge,IE11)中尝试此示例,则select元素不会检测到更改. 还有其他人注意到这个问题或我缺少什么吗?因为诸如Select之类的下拉元素中的更改检测是基础知识,所以……我简直不敢相信它不起作用.

I just have a simple question regarding select element. I spent quite some time debugging my code, because select element did not pick up changes. But then I found out something interesting. They have form example on their page angualr.io: https://angular.io/resources/live-examples/forms/ts/plnkr.html. If you try this example in browser other than Chrome, like Firefox, Edge, IE11 – the select element doesn’t detect changes. Have anyone else notice this problem or I’m missing something? Because change detection in dropdown element like Select is a basec thing … I just cannot believe it doesn’t work.

我认为此答案可以为您提供解决方法和Mark的答案:

I think that this answer could provide you a work around and the Mark's answer:

这是一些代码:

@Component({
  (...)
  template: `
    <select [ngModel]="selectedDevice" (ngModelChange)="onChange($event)">
      <option *ngFor="#i of devices">{{i}}</option>
    </select>
  `)
  export class SomeComponent {

    onChange(newValue) {
      console.log(newValue);
      this.selectedDevice = newValue;
      // ... do other stuff here ...
    }
  }