(点击)功能未在Chrome Angular 6中触发

时间:2019-03-16 12:14:14

标签: javascript html angular typescript google-chrome

当我使用谷歌浏览器时,

(点击)功能不会在我的选择标签中触发,但在Mozila中可以使用

这是我的代码

<div class="col-xl-4 col-lg-9">
    <select formControlName="deptId" class="form-control m-input" >
    <option>SELECT</option>
    <option *ngFor="let item of listAllDepartment"  (click)="getdoctorlistid(item.dept_id)" value={{item.dept_id}}>{{item.dept_name}}</option>
    </select>
</div>

谢谢

2 个答案:

答案 0 :(得分:1)

您应该将ngModelChange与select一起使用,而不是单击

 <selectformControlName="deptId" class="form-control m-input"  [(ngModel)]="itemSelected" (ngModelChange)="getdoctorlistid(itemSelected)">

答案 1 :(得分:0)

无法添加这样的事件到<option>
您可以添加

<select 
    [(ngModel)]="selectedItem" 
    (ngModelChange)="getdoctorlistid(selectedItem)">
        <option>SELECT</option>
        <option 
            *ngFor="let item of listAllDepartment"  
            (click)="getdoctorlistid(item.dept_id)" 
            value={{item.dept_id}}>
                {{item.dept_name}}
        </option>
</select>

编辑:就像@Sajeetharan回答