hey, I have a problem accessing a @ViewChild()
property in app.component.ts. Is there anything I need to do in order to use it in app.component?
I think I have done it correctly but it simply does not get set in ngAfterViewInit
Fun thing though is if I use setTimeout
for 2 seconds, then it gets set after those 2 seconds.
Any help is appreciated
export class MyApp {
@ViewChild(DropDown) dropDown: DropDown
@ViewChild(Nav) nav: Nav
ngAfterViewInit() {
console.log(this.dropDown) // undefined
console.log(this.nav) // outputs nav correctly
// this actually DOES have dropDown, but I can't access it though
console.log(this) // {MyApp {platform: Platform, ... dropDown: DropDown...}
setTimeout(() => {
console.log(this.dropDown) // Now it is set (after 2 seconds)
}, 2000)
}
}