NativeScript angular nativeView undefined

旧时模样 提交于 2021-01-29 21:40:44

问题


I am trying to get StackLayout nativeView from NativeScript Angular but always returning undefined. I tried like this:

html:

<StackLayout id="stackLayout" #stackLayout> </StackLayout>

TS:

ngAfterViewInit() {
    setTimeout(() => {
        let container: StackLayout = this.page.getViewById("stackLayout");
        console.log(container.nativeView); 
        console.log(this.stackLayout.nativeElement.nativeView);
    }, 100)
}

Please give me suggestion.


回答1:


Use the loaded event of the View itself which ensures the nativeView is ready.

HTML

<StackLayout (loaded)="onLoaded($event)"></StackLayout>

TS

onLoaded(event: EventData) {
  const stackLayout = <StackLayout>event.object;
  console.log(stackLayout.nativeView);
}


来源:https://stackoverflow.com/questions/56112770/nativescript-angular-nativeview-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!