3

Can i disable view caching? I need my view to be up to date when the user hits the "back" button. I can update date but the view wont update.

Example: First page: List of tasks Second page: Task

I enter the list of tasks page, get the tasks from the database and list them. I show the user which task is done and which is not (with a special css class)

When the user taps a task he is redirected to a task page. There he can update the task to done. But when he goes back the tasks list will not be updated.

How can i make this happen?

Thank you

Mr. Sam
  • 790
  • 2
  • 9
  • 31

4 Answers4

6

Using Ionic 2, this actually isn't as bad as it was in the first iteration. Check out the NavController docs at http://ionicframework.com/docs/v2/api/components/nav/NavController/

Using the page event "ionViewDidEnter()" will allow you to add logic that you want to fire every time the page loads, even if it's been cached in the Nav Stack.

ionViewDidEnter     Runs when the page has fully entered and is now the active page. This event will fire, whether it was the first load or a cached page.
Natasha Loiseau
  • 169
  • 1
  • 7
  • I am using tabs template and ionViewDidEnter does not fire upon calling the page for the second time. – HelmBurger Jun 12 '17 at 22:59
  • That's actually a different issue, but I'll handle that as well. Take a look at the docs on Tab http://ionicframework.com/docs/api/components/tabs/Tab/ in ionic. There is an event that is emitted, "ionSelect" when a tab is selected that you can subscribe to. Tabs aren't loaded in the same way as other pages, as, technically, tabs are all elements in the same page, and therefore the page was never left. "ionSelect" should you help you out with that difference. – Natasha Loiseau Jun 14 '17 at 02:59
0

There is a little work to do to achieve this. In fact each component has its own state (properties).

In your case to notify the list component that one element was updated, the list generic way is to leverage a shared service with an observable. Through this observable the details component can emit an event to notify the list one. The event will contain the updated value of the element.

The list has registered on this event and will be notified. In this case it will be able to update the element in the list.

For more details of this approach, you could have a look at the following links:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
0

Your question doesn't provide much information but this might apply to your situation.

You could try to implement CanReuse in you component to always return false which prevents the router reusing a component instance.

routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return false; }
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

I believe the Ionic V2 accepted way is to use the lifecycle event from ionic called ionViewWillEnter() and this function will fire every time that page is loaded.

Chad Elias
  • 637
  • 6
  • 7