问题
I have a view that is linked up to a controller:
<div ng-controller="myController">
...
</div>
the controller:
app.controller('myController', ['$scope',
// Some code here that calls a webservice and updates the scope
]);
When the controller initially runs, it calls a webservice, returns the data and binds it to the scope. It works great. However when I navigate to another view/state using ui-sref
or $state.go()
and I navigate back to this view, the controller doesn't call the webservice again.
Is there a way to make sure that every time the state lands on this view and controller, the controller is re-run so to speak?
回答1:
Ionic by default caches view and controller execution to improve performance. You can disable it with cache: false
:
$stateProvider.state('myState', {
cache: false,
url : '/myUrl',
templateUrl : 'my-template.html'
});
Or you can disable it at URL level using ui-sref-opts
How to put reload option in ui-sref markup
See Caching docs.
来源:https://stackoverflow.com/questions/33384826/how-to-re-run-the-controller-every-time-you-navigate-to-the-corresponding-view-s