1

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?

2
  • 3
    in view, set cache false. Commented Oct 28, 2015 at 7:04
  • you can set cache false in route also. Commented Oct 28, 2015 at 7:08

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant! This is exactly what I was looking for