问题
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