This question is related to a question that has been asked on StackOverflow quite a few times.
Basically, when you do something like
@Component({
selector: 'my-app',
template: `<div>I'm {{message}} </div>`,
})
export class App {
message:string = 'loading :(';
ngAfterViewInit() {
this.updateMessage();
}
updateMessage(){
this.message = 'all done loading :)'
}
}
You get an error saying "Expression has changed after it was checked" . The reason you get this error has been explained in this post: Expression ___ has changed after it was checked
My question is, why does the following work?
@Component({
selector: 'my-app',
template: `<div>I'm {{message}} </div>`,
})
export class App {
message:string = 'loading :(';
ngAfterContentChecked() {
this.updateMessage();
}
updateMessage(){
this.message = 'all done loading :)'
}
}
Why does this not return an error, and actually returns the proper result? Why does ngAfterViewChecked work, and ngAfterViewInit not work?
Explain like I'm 5.