Angular 2 Beta –选择不起作用(Chrome中除外) [英] Angular 2 beta – Select not working (except in Chrome)

查看:55
本文介绍了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 ...
    }
  }

这篇关于Angular 2 Beta –选择不起作用(Chrome中除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆