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

Popular posts from this blog

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -