Reputation: 239
In my ionic app, I have 2 tabs called applied
and rejected
. When I first navigate to the appliedPage
the method in a constructor is called and it is showing the output, same to the RejecedPage
. But when I go the third page and click on apply/reject button then the changes should reflect on either AppliedPage
or RejectedPage
. But hereafter clicking on the apply or reject, when I navigate to the applied
or rejected
page the Http
in the constructor is not being called. Whenever I open a particular page that page should automatically call a method (from where I retrieve the data from DB
using http
). How can I do it?
constructor(public navCtrl: NavController, public navParams: NavParams,
private getAppliedlist: ActionsProvider)
{
console.log('fetching data`);
this.getAppliedlist.getAppliedList().subscribe((data: any) => {
this.applied = data;
console.log(this.applied);
})
}
This above code is from the AppliedPage
.
Upvotes: 0
Views: 364
Reputation: 18301
Instead of doing it within the constructor, you should make use of the ionic
lifecycle functions. In this case, the ionViewWillEnter
function will be perfect
According to the docs, it is called:
when entering a page, before it becomes the active one. Use it for tasks you want to do every time you enter in the view (setting event listeners, updating a table, etc.).
ionViewWillEnter() {
console.log('fetching data`);
this.getAppliedlist.getAppliedList().subscribe((data: any) => {
this.applied = data;
console.log(this.applied);
})
}
Upvotes: 1