I have an Ionic 2 app. The premise of the app is to take a class. Once a class has been opened the user is marked as taking this class in the remote API.
The flow of data is:
- User opens 'Classes' tab.
- App requests 'Classes' data from API. Each class holds a 'status' for that user.
- User selects a class. This opens a new view in the app using
NavController.push(Page, { 'classes': classObjFromApi });. - There are a few pages added to the stack, each has the
classesobject passed to it. - On the final page the API is informed that the current class has been taken and the user can navigate back to the root using
NavController.popToRoot()
On the root page each class' status is shown ('Not started', 'In progress', 'completed'). At point 5 in the above flow the user is taken back to the root, but this has the data from when it was originally constructed, which shows the class as 'Not started', even though it's 'completed' now.
How can I update the data on the root page from a different page in the stack? I had assumed that popToRoot() would accept navParams so I could check for the presence of that data in the root page and use it if it exists or request from the API if not.
I can get around this by re-requesting data from the API on the ionViewDidEnter method, but that means an API/HTTP request every time the user views this page, even though the app has the data. Seems messy.
I'd rather not use internal storage if I can help it, as it creates a delay when loading the page, as I have to wait for data to be pulled from storage before displaying it.
So my question: what's the best way of doing this? If it is to pass data to the view, how do I do that if popToRoot() doesn't support nav params?