AngularJS / Ionic refresh when view loads

By default a controller only fires it’s init code when a view is first loaded. If you are using Tabs and move away, then come back, the controller will not fire again. To get it to fire again when the page reloads, refer to these:

function(event, toState, toParams, fromState, fromParams){ ... })

and maybe this method:

.controller('MyCtrl', function($scope) {
  $scope.$on('$ionicView.enter', function() {
     // Code you want executed every time view is opened

There is also mention of how to turn this off for the entire app, but I won’t copy that here as I don’t want to do that.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s