我试图从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)
}
请给我建议。
答案 0 :(得分:0)
使用View本身的loaded
事件,以确保nativeView
准备就绪。
HTML
<StackLayout (loaded)="onLoaded($event)"></StackLayout>
TS
onLoaded(event: EventData) {
const stackLayout = <StackLayout>event.object;
console.log(stackLayout.nativeView);
}