forms - Angular 2 checkbox - How to use [checked] with (ngModelChange)? -
i'm having trouble programmatically setting checkbox in angular 2. following code fires oncheck()
whenever user checks checkbox. can check checkbox programmatically setting this.select
'true'.
<input type="checkbox" [(ngmodel)]="v.checked" [checked]="select" (ngmodelchange)="oncheck(v.checked)">
my problem when set this.select
'true', ngmodelchange
doesn't seem detect change , oncheck()
doesn't fire... :-(
any tips? there alternative way programmatically set checkbox , have associated function fire?
you can use checkbox component variable :
@component({ selector : 'my-component' template : `<input type="checkbox" [(ngmodel)]="selected"/>` }) export class mycomponent(){ public selected: boolean = false; }
Comments
Post a Comment