Hi Please go through it. It may help you
In summary, these are the events:
ionViewDidLoad : Fired only when a view is stored in memory . This event is NOT fired on entering a view that is already cached. It’s a nice place for init related tasks.
ionViewWillEnter : It’s fired 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.).
ionViewDidEnter : Fired when entering a page, after it becomes the active page . Quite similar to the previous one.
ionViewWillLeave : Fired when you leave a page, before it stops being the active one. Use it for things you need to run every time you are leaving a page (deactivate event listeners, etc.).
ionViewDidLeave : Fired when you leave a page, after it stops being the active one. Similar to the previous one.
ionViewWillUnload : Fired when a view is going to be completely removed (after leaving a non-cached view).
Your tabs is in one container .
Now when you clicked on Edit Profile you are moving from one container to another container.
So once you come back try to call methods in container and not in tabs.
I think you are right but if i redirect to different tabs page it works perfectly. In my situation its not working with the last page.
is there any way how i can achieve what i want to do.
1.If on Edit Profile Page you are saving data on server once updation in profile done. Then you can access it again once you redirected to My account Page by calling api.
2.If its working with all pages then check router configurations
I m doing that but the issue is when i came back from edit page its not triggering any event, so when it it come back from edit page api call is not made by the app and the data not updated.
Same type of situation:
Lets say a news app
Page 1: List of news
Page 2: Single news
When you go to Page 2 from Page 1 and the back to page 1 by pressing any back button the content of page not refreshing.
I know you have solved this issue but I am having this exact issue at the moment and couldn’t solve it with your proposed solution. Some questions I have:
Can you show us the app routing definition?
Is the Edit Account form page setup as its own module?
Not that anybody need care about my opinion, but for what it’s worth, I think lifecycle events should not be (ab)used to solve the general problem of “displaying stale data”. What people tend to do:
There are a myriad of options for accessing Observables from a template. Many of them involve memory leaks or overly verbose boilerplate. Two that don’t are the AsyncPipe and NetanelBasal’s ngx-take-until-destroy.
I frequently think in terms of “WORM (Write Once / Read Multiple) brokers”, where a resource has many readers and a single writer. The broker in this case is the ProfileService, which is injected by anybody interested in the Profile resource. It exposes three operations: watch, peek, and poke. Readers who want updates want watch. Transient readers that don’t care about updates can use peek. Writers generally take a snapshot with peek, modify it, and push the updates back with poke.
All of this happens with no additional code on the part of readers, no dependencies on the vagaries of framework internals (such as what lifecycle events fire when on what UI components), and no wasteful performance hits (such as you see with “solutions” to this problem that completely rerender a bunch of irrelevant stuff, often via action-at-a-distance).
It is also easy (and transparent) to add network and/or backing on-device storage to ProfileService. Nobody outside that class has to know or care when or how external forces collude to bring fresh data.
What happen if you want to implement some logic over data received?, I mean when profile$ property of ProfileDisplayPage is updated and I want to use new data to do another operations?
yeah, but I currently have problems when I wrap the subscribed data in ngIf wrapper, Template is rendered twice, if I remove ngIf It works. Would you be so kind as to review my case?
Hi there.
I read this read thread and I think I bumped into a similar situation. Like you’ve said, I want the updates to propagate across my app. I am not able to understand despite the long explanations cause I am new to ionic.
My case: It is a quiz app. There are ten levels and each level has 10 questions. Cards have been employed to contain the quiz question for each level (so, there are 10 cards for 10 levels).
In a level, if you score five or six you get a star remark for that level, if you score 7 or eight you get 2 stars and, 3 stars for 9 and 10 points. Here I am using ion-icon fora assigning stars for each level.
So the thing here is, I am not able to display the stars even when I scored the minimum point to obtain at least one star. I am sure that it’s the problem of data updates. Although the points are updated in the database(SQLite DB), I am not able to render the stars on the page.
I’m at a bit of a loss for words. You obviously put in a ton of work on this, and I don’t know how to best say this diplomatically, but…I would structure things very differently here in general, because there is a lot of boilerplate.
What I would have done instead is to define interfaces for Question, Quiz, &c, and then structure the actual quizzes and questions as JSON assets. That way you only have to have one single QuizPage that can handle any properly-formatted quiz asset. Designing it that way achieves two hugely important maintenance goals:
Adding questions and new quizzes can be done simply by adding assets - absolutely zero code modification required. Now, adding a new quiz is a major undertaking, involving changes in SQL and new pages.
Any interface improvements immediately propagate to all quizzes. The way it is now, you would have to change eleventy kajillion hardcoded quiz pages whenever you wanted to change anything about the interface.
Updating a single answer to a single question also necessitates a complete reload of every score of every question of every quiz, the way things are written. I would expect that to negate any possible performance benefit of using SQLite at all (although one could argue that SQLite isn’t really needed or wanted here anyway).
But you didn’t come here asking for design advice, and I’m basically advising totally rewriting the app, which I expect you are very unlikely to want to hear.
So, if you’re looking to change things as little as possible, at a very minimum you need to rearchitect getSum, and make it return an Observable (that actually updates when necessitated) instead of a Promise. Promises are for one-shot operations, whereas these sums are long-lived, periodically changing beasts.
Thank you for the response and tips on design. All of the things you mentioned about the design must have been an oversight since I am still exploring it.
As you suggested using Observable instead of Promise, I looked up how to implement observable but I am not very confident implementing observable, especially in my case, where I need to return getSum as an observable. Could you help me with that?
I would suggest reading the Angular documentation about Observables and general RxJS documentation, and again keeping in mind that what I would really do here is to get SQL out of the loop entirely, given that you already have a Promise, you can make either a BehaviorSubject (if you can always guarantee that there is some value, or if “no value” becomes possible at runtime - this should not be the case in your app, as I understand it) or a ReplaySubject of stack size 1, expose that as your Observable, and then next at it every time you calculate a new total score.