Angular Change Detection does not work properly - Angular16

73 Views Asked by At

I start working in a new angular project, I find such a weird behavior that we can see throw the following example

ngOnInit() {
    setTimeout(() => {
      this.test = 100
      console.log('changed value .. ' + this.test)
      // this.crf.detectChanges();
    }, 3000)
}
<div>test {{test}}</div>
<button (click)="clickTest()">test</button>

the value test is not changed by the Timeout ( we have to add this.crf.detectChanges() to do so )

when we click on the button it changes as well. I've already take a look to the documentation But I'm not able to figure out the reasons for such behavior ! and How can we fix it ?

0

There are 0 best solutions below