本文介绍了NativeScript 角度 nativeView 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

请给我建议.

推荐答案

使用视图本身的 loaded 事件,确保 nativeView 已准备就绪.

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

这篇关于NativeScript 角度 nativeView 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 00:26