Angular change the state of a checkbox after user click

I have the following code that should set the checked value to false on click:

@Component({
  template: `
    <input type="checkbox" [checked]="checked" (change)="onChange()">
   `
})
export class AppComponent  {

  checked = false;

  onChange() {
    setTimeout(() => {
      this.checked = false;
    }, 1000)
  }

}

The problem is that if we click on the input and we wait for a second, it’ll stay checked. Why is this happening? Why Angular doesn’t change it to false again?

2 thoughts on “Angular change the state of a checkbox after user click”

Leave a Comment