Page1 => click button => Page2 => do nothing => return Page1.
Page1 => click button => Page2 => submit a blog => return Page1.
Ask:
Could Page1 reload data only when ’ submit a blog’ ?
Whether you add an IonViewDidPop interface to receive the returned data ?
Sure you can. But I think it would be a good idea to load page2 inside a modal. That way you can ‘listen’ for the onDismiss event and see whether something was changed or not. You can then act on the data that’s coming back from the modal and thus ‘reload’ (although I would like to note that reloading seems redundant in a SPA build with Angular).
I would do something like this:
Inside page1, create the modal and start listening to the onDismiss();
Load up page2 inside the modal, then do whatever stuff you want. If the modal get’s closed with the normal close button, it shouldn’t return any data.
If the modal was dismissed by pressing the ‘submit a blog’ button, you should pass data back into page1. Now you now that someone actually pressed submit a blog! Also it’s now easy to also ‘reload’ your local list of blogs, by simply adding the newly received blog to your (local) list. At the same time you can push it to server off course, although I would probably already post it back to your endpoint from within the modal.
Okay, so I understand that the blog needs to be reviewed and that it shouldn’t display immediately. Could you explain why you want to refresh page 1 anyways when returning from page2 to page1? How do you know a refresh is necessary at that point? It seems to me you’re creating extra unnecessary traffic to your server, but okay.
I don’t see why a modal can’t do such stuff? Care to explain? You could just pass back a value shouldRefresh to your page1 if the modal is dismissed.
If you don’t like the idea of a modal, you could set a boolean inside a service that’s shared between both pages. On loading page1 check whether the boolean resolves to true or not.
navCtrl.pop() isn’t capable of sending data through the params as far as I can tell.
I’m pretty sure it’s been requested a lot, going back to before I got involved with Ionic. I don’t think it’s ever been officially supported. Using a modal is better, because the ViewController passing parameters after the modal is dismissed is a supported feature. Clever “hacks” make more sense with a framework that’s been stable for years, not one that might introduce a breaking change to a hack tomorrow.
I agree with @AaronSterling on this . That’s why I proposed the modal solution A service could be a second option, but isn’t bound to timing of the dismissal. I still don’t know why a modal is no option @anrip?
Who’s doing the reviewing? This extra page wasn’t in your original post btw. Little bit confusing. You could always create a modal for the blog page as for the review blog page. Then you can listen to both events. So:
Possible steps:
I want to add a blog! (user pushes add blog button, modal pops up);
User closes modal, we listen in page 1 to the dismissal and do nothing
User submits blog, now we could pop up the second modal and listen to it again.
Or you could just handle both views as components inside your modalPage, that’s another option. By that I mean creating a add blogpost component and a review component which both are presented within the same modal.
The best and simple option is use
ionViewWillEnter(){
console.log(“Returned to page”);
this.getList();
}
With this we know when returned from another page