How to dismiss Loader after data is ready
You can find a working plunker here.
Like you can see in the code of that plunker, I would make a few changes in order to make your code work properly:
export class FarmList implements OnInit {
items: Object;
// Define the loading var here, so we can access later when the information is ready
loading : any;
constructor(public testService: TestService, public nav: NavController){
}
// Instead of 'ngOnInit', I would use 'ionViewWillEnter'
ionViewWillEnter(){
this.getData()
}
getData(){
this.loading = Loading.create({
content: 'Please wait..',
spinner: 'crescent'
})
this.nav.present(this.loading)
this.testService.fetchData().then(data => {
this.items = data;
// After we get the data, we hide the loading
this.hideLoading()});
}
// I 've added this method so we can grab the loading var and use it
// to hide the loading component.
private hideLoading(){
this.loading.dismiss();
}
...
}
================================
UPDATE:
As of the release of Ionic 2.0.0-beta.8 (2016-06-06) changelog:
onPageWillEnter
was renamed to ionViewWillEnter