Angular2 - Prevent Checkbox from being checked Angular2 - Prevent Checkbox from being checked angular angular

Angular2 - Prevent Checkbox from being checked


ngModelChange is fired when value binded to checkbox has changed, it's late for stop the toggle operation.

Here you should bind with click event. Then you can use $event.preventDefault() to stop checkbox from been toggled.


You can event add some logic before $event.preventDefault() to determin whether the checkbox should be prevent from changing status.

see Plunker demo.


HTML

 <input type="checkbox" [checked]="isChecked" (click)="onClick($event)">

Code

onClick(e){  e.preventDefault(); // In my case, I'm using the popup. // so once user confirms then hits api and update checkbox value. this.isChecked = true;}