Are there some ways for @ViewChild
decorator to get the child component's instance in ngOnInit
as the same from the old @ViewChild
of angular 6?
I tried something like:
@Component({
....
})
export class AppComponent implements OnInit {
@ViewChild(HelloComponent, {static: true})
@ViewChild(HelloComponent, {static: false})
hello: HelloComponent;
ngOnInit() {
console.log('Hello Instance',this.hello);
}
}
but it causes me error saying Multiple decorators are not allowed for the same member
I'd like to share what I just discovered for @ViewChild for other readers knowledge
to let @ViewChild with
static
property set to false inngOnInit
I have to put it inside setTimeout() like so:
this way, it can get the child component inside
ngOnInit