NativeScript角度nativeView未定义

时间:2019-05-13 12:51:16

标签: nativescript nativescript-angular

我试图从NativeScript Angular获取StackLayout nativeView,但总是返回undefined。我这样尝试过:

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)
}

请给我建议。

1 个答案:

答案 0 :(得分:0)

使用View本身的loaded事件,以确保nativeView准备就绪。

HTML

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

TS

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