【问题标题】:Angular 2 (click) does not work in ChromeAngular 2(点击)在 Chrome 中不起作用
【发布时间】:2016-08-29 14:32:27
【问题描述】:

我在我的 html 模板中使用这样的东西:

 <div class="input-group" id="geo-type">
        <div class="input-label" [style.color]="geographicLocationColor">{{geoLocationTitle}}</div>
        <select class="dropdown-toggle dropdown-select" role="button" aria-haspopup="true" aria-expanded="false">
            <option value="" selected hidden>{{geographicLocationPl}}</option>
            <option *ngFor="#geo of geographicLocations" (click)="locationOnSelect(geo)">{{geo.description}}</option>
        </select>
    </div>

如果我使用 firefox 在下拉菜单中选择某些内容,则会调用方法 locationOnSelect(我正在执行其他一些由位置标识的 GET),但在 Chrome 中不会发生任何事情 - 方法 locationOnSelect 没有被调用。

我的 IE(版本 11)也有问题,locationOnSelect 没问题,但在下一个 GET(用户在第二个下拉菜单中选择某些内容)时,IE 崩溃 - 停止工作。所以我的应用程序 100% 只在 Firefox 中工作。有什么想法吗?

【问题讨论】:

  • 我在 select 属性上看不到 (click) 指令。添加并检查。
  • 我将我的 (click)="locationOnSelect(geo)" 移动到选择标签,现在,应用程序崩溃,因为地理未定义。

标签: html twitter-bootstrap angular


【解决方案1】:

您需要在&lt;select&gt; 上添加(click)="..."(change)="..." 而不是&lt;option&gt;

另见Click event on select option element in chrome

<div class="input-group" id="geo-type">
    <div class="input-label" [style.color]="geographicLocationColor">{{geoLocationTitle}}</div>
    <select [ngModel]="selectedGeo" (ngModelChange)="locationOnSelect($event)"
       class="dropdown-toggle dropdown-select" role="button" aria-haspopup="true" aria-expanded="false">
        <option selected hidden>{{geographicLocationPl}}</option>
        <option *ngFor="#geo of geographicLocations" [ngValue]="geo">{{geo.description}}</option>
    </select>
</div>

【讨论】:

  • 谢谢,但我将我的 (click)="locationOnSelect(geo)" 移动到选择标签,现在,应用程序崩溃,因为地理未定义。
  • 您可以使用[ngModel](ngModelChange) 来获取请求的行为。
  • 抱歉,我将ngModel 的内容添加到了错误的标签中。它应该在&lt;select&gt;
  • rc-versions 包含新的路由器,有很多变化。不要操之过急。文档需要更新。很多问题。如果你很勇敢,你当然可以换 ;-) 我会等至少几天。他们正在努力解决问题。
  • 您可以尝试在您的组件中创建一个属性,例如this.placeholderValue = {}; this.selectedGeo = this.placeholderValue; (for example in the constructor and then change the placeholder to `跨度>
猜你喜欢
  • 2017-08-14
  • 2017-11-14
  • 1970-01-01
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
  • 2016-01-26
  • 1970-01-01
相关资源
最近更新 更多