Expression ___ has changed after it was checked

后端 未结 17 1895
太阳男子
太阳男子 2020-11-22 05:53

Why is the component in this simple plunk

@Component({
  selector: \'my-app\',
  template: `
I\'m {{message}}
`, }) export class App {
17条回答
  •  -上瘾入骨i
    2020-11-22 06:30

    Can't you use ngOnInit because you just changing the member variable message?

    If you want to access a reference to a child component @ViewChild(ChildComponent), you indeed need to wait for it with ngAfterViewInit.

    A dirty fix is to call the updateMessage() in the next event loop with e.g. setTimeout.

    ngAfterViewInit() {
      setTimeout(() => {
        this.updateMessage();
      }, 1);
    }
    

提交回复
热议问题