Hi, I am new to ionic. I have a issue regarding transfer of data from one screen to other. I will explain my problem with an example.
I have two pages “A” and “B”.In both the screens I have a button called “Purchase”. Now I am navigating form page “A” to page “B”. In page “B” I am clicking on “Purchase” button upon clicking purchase button I am hiding the Purchase button and storing a BOOL variable in window.localStorage and I am clicking back button. Now I am in page “A”.When I am in page “A” Purchase button should be hidden depending upon the BOOL variable in window.localStorage . My problem is when I click back button in Page “B” and returning to Page “A”, which method should I call to check the Bool variable in local Storage. Please help me and let me know if you have any queries. Thanks in Advance
LocalStorage is not the simplest approcach, you should rather define a Purchase service.
Anyway, your problem is probably also due to Ionic view caching, check the official docs or search the forum to know about it.
@gmarziou is correct. You should not use localstorage for this feature when there are much better solutions.
As @gmarziou told you, create a Purchase service, it’s the best solution.
A dirty solution would be to use a global object. You can even share data between view transitions.
Use localstorage only if you want to persist some data.
If you need a tutorial, click here.
Yeah got it, but out of curiosity in iOS by using protocols we can pass data when we are popping to the last visited view controller. Can we implement the same in ionic framework?? I mean to say while returning to the last visited page by clicking on back button, can we transfer any data to that page??
It depends on how are you handling back button. Are you handling it manually or are your back buttons generated automatically?
Unfortunately, this is not possible, at least not in my knowledge.
Factory service is still your best choice.