简体   繁体   中英

Angular 2,(change) event not firing on bootstrap checkbox

i have an issue, (change) function is not firing in that checkbox.

 <input [(ngModel)]="driver.glasses" name="glasses" type="checkbox" class="make-switch"
   (change)="changeFuntion()"  data-on-color="primary" data-off-color="info">

But in this one it works

    <input [(ngModel)]="driver.glasses" name="glasses" type="checkbox" 
   (change)="changeFuntion()"  data-on-color="primary" data-off-color="info">

I have noticed that class="make-switch" is the problem, because in the first checkbox with that class, (change) don´t work. How I can solve this, I need to apply class="make-switch" to make switch checkbox.

You can use ngModelChange like this :

This is your component.ts

 checkboxValue: any; changeEvent(event: any) { console.log(event); } 
 <input type="checkbox" [ngModel]="checkboxValue" (ngModelChange)="changeEvent($event)" data-md-icheck/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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