I am new to mobile application development with Ionic. On login and logout I need to reload the page, in order to refresh the data, however, $state.go('mainPage')
takes the user back to the view without reloading - the controller behind it is never invoked.
Is there a way to clear history and reload the state in Ionic?
.state(url: '/url', controller: Ctl, templateUrl: 'template.html', cache: false) cache: false ==> solved my problem !
In my case I need to clear just the view and restart the controller. I could get my intention with this snippet:
The cache still working and seems that just the view is cleared.
ionic --version
says 1.7.5.I was trying to do refresh page using angularjs when i saw websites i got confused but no code was working for the code then i got solution for reloading page using
use this in a function this will work.
I found that JimTheDev's answer only worked when the state definition had
cache:false
set. With the view cached, you can do$ionicHistory.clearCache()
and then$state.go('app.fooDestinationView')
if you're navigating from one state to the one that is cached but needs refreshing.See my answer here as it requires a simple change to Ionic and I created a pull request: https://stackoverflow.com/a/30224972/756177
I needed to reload the state to make scrollbars work. They did not work when coming through another state - 'registration'. If the app was force closed after registration and opened again, i.e. it went directly to 'home' state, the scrollbars worked. None of the above solutions worked.
When after registration, I replaced:
with
The app reloaded, and the scrollbars worked.
If you want to reload after view change you need to
If you want to make that view the new "root", you can tell ionic that the next view it's gonna be the root
If you want to make your controllers reload after each view change