Why is the component in this simple plunk
@Component({
selector: \'my-app\',
template: `I\'m {{message}} `,
})
export class App {
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);
}