Which method is fire every time the view appear - Nativescript Angular

Viewed 1230

I am coming from iOS background and I am very new to Nativescript. I want to know is there any equivalent method to iOS viewWillAppear in Nativescript.

I want to update listview everytime the view is appearing. I have tried following methods. Nothing can do the job

ngOnInit(): void {
  console.log("onInit called");  
}
ngDoCheck(): void{
    console.log("ngDoCheck called");
}
ngAfterContentInit(): void{
    console.log("ngAfterContentInit called");
}
ngAfterContentChecked():void{
    console.log("ngAfterContentChecked called");
}
ngAfterViewInit():void{
    console.log("ngAfterViewInit called");
}
ngAfterViewChecked(): void{
    console.log("ngAfterViewChecked called");
}
ngOnDestroy():void{
    console.log("ngOnDestroy called");
}
3 Answers

You can use the NativeScript loaded event (API reference)

<ListView (loaded)="onListViewLoaded($event)"></ListView>

And then in the component file

onListViewLoaded(args) {
    let list = <ListView>args.object;
}

I am not an expert with nativescript, i will try to answer you using Angular.

Angular came with component life cycle once you create the component. So, if you destroy your component and recreate it again, you can use ngAfterViewInit.

Or if you create the component only one time and just hide/show it, you should do it using Angular directive to hock on visibility property of your view.

Note: if you gave the component any input property and it will change on show/hide the component you can use ngOnChanges, but Angular call it only if any component input parameters changed or the component placed on the changed detection tree.

Related