title: How do I refresh an Angular controller on state load?
body: <p>I'm building an angular/ionic application as part of my thesis, and part of the functionality is to change a 'collection list' based on a selection on a different partial (the <code>character select</code>). The value that's being updated is saved to a .value called 'global', so that it's always accessible.</p>
  
  <p>When I select a radio button on <code>character select</code>, the value updates correctly, but upon navigating back to the <code>collection list</code>, the change is never applied.</p>
  
  <p>The solution I see is to have <code>collection list</code> always do a full refresh when navigated to, however every relevant solution I have seen only <code>refreshes</code> the current page, whereas I need to have the page refreshing any time I navigate to it.</p>
  
  <p>Any suggestions? </p>
  
  <p>Edit: My apologies for not posting the code. I had assumed that the code wouldn't be necessary for this scenario.</p>
  
  <p>details.html</p>
  
  <pre><code>&lt;ion-view&gt;
  &lt;ion-content padding="true"&gt;
  &lt;br&gt;&lt;br&gt;
      &lt;div class="bar bar-header item-input-inset"&gt;
          &lt;label class="item-input-wrapper"&gt;
              &lt;i class="icon ion-ios7-search placeholder-icon"&gt;&lt;/i&gt;
              &lt;input type="search" placeholder="Search" ng-model="searchFilter.dragon_name" /&gt;
          &lt;/label&gt;
      &lt;/div&gt;
      {{character.character_id}} &lt;!--Testing for updated variable--&gt;
      &lt;ion-list&gt;
          &lt;ion-item class="listHead" ng-hide="searchFilter"&gt;Ancient&lt;/ion-item&gt;
          &lt;ion-item ng-repeat="content in contents | filter:{family_name:'Ancient'}:true  | filter:searchFilter"&gt;
          &lt;div class="listLeft"&gt;
          &lt;img data-ng-src="img/icons/{{content.family_id}}/{{content.dragon_th}}.png" alt="{{content.dragon_name}}" class="thumb"/&gt;
          &lt;a href="#details/{{content.dragon_id}}"&gt;
              &lt;h2 class="listTop"&gt;{{content.dragon_name}}&lt;/h2&gt;
          &lt;/a&gt;&lt;br&gt;
          &lt;h3 class="listBottom"&gt;{{content.family_name}}&lt;/h3&gt;&lt;br&gt;
          &lt;h3 class="listBottom" ng-repeat="location in content.locations"&gt;{{location.zone_name}}&amp;nbsp;&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="listRight"&gt;
          &lt;label class="toggle"&gt;
             &lt;input type="checkbox" ng-model="hasDragon"&gt;
             &lt;div class="track"&gt;
              &lt;div class="handle"&gt;&lt;/div&gt;
             &lt;/div&gt;
          &lt;/label&gt;
          &lt;/div&gt;
          &lt;/ion-item&gt;
      &lt;/ion-list&gt;
      &lt;/ion-content&gt;
      &lt;/ion-view&gt;
  </code></pre>
  
  <p>characters.html</p>
  
  <pre><code>&lt;ion-view&gt;
  &lt;ion-content padding="true"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;div class="nameSpread charTitle"&gt;&lt;h4&gt;Character Name&lt;/h4&gt;&lt;/div&gt;&lt;div class="serverSpread"&gt;&lt;h4&gt;Server&lt;/h4&gt;&lt;/div&gt;
      &lt;ion-radio class="characterSelect" ng-repeat="content in contents" ng-click="selectCharacter({{content.character_id}})" ng-model="data.characterSelection" ng-value="content.character_id"&gt;
          &lt;div class="nameSpread"&gt;{{content.character_name}}&lt;/div&gt;
          &lt;div class="serverSpread"&gt;{{content.server_name}}&lt;/div&gt;
      &lt;/ion-radio&gt;
  &lt;/ion-content&gt;
  &lt;/ion-view&gt;
  </code></pre>
  
  <p>app.js (only posting the relevant code due to the size of the document)</p>
  
  <pre><code>var app = angular.module('ionicApp', ['ionic', 'ui.router'])
  
  .run(function($ionicPlatform) {
      $ionicPlatform.ready(function() {
          if(window.cordova &amp;&amp; window.cordova.plugins.Keyboard) {
              cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
          };
      if(window.StatusBar) {
          StatusBar.styleDefault();
          };
      });
  });
  
  app.config(function($stateProvider, $urlRouterProvider) {
      $stateProvider
  
      //Home Tab
      .state('home', {
          url: "/",
          templateUrl: "partials/home.html",
          controller: 'appController'
      })
  
      //Dragons (Colour) Tab
      .state('dragonsColour', {
          url: "/dragonsColour",
          templateUrl: "partials/dragonsColour.html",
          controller: 'dragonsController'
      })
  
      //Dragons (Family) Tab
      .state('dragonsFamily', {
          url: "/dragonsFamily",
          templateUrl: "partials/dragonsFamily.html",
          controller: 'dragonsController'
      })
  
      //Dragons (Zone) Tab
      .state('dragonsZone', {
          url: "/dragonsZone",
          templateUrl: "partials/dragonsZone.html",
          controller: 'dragonsController'
      })
  
      //Characters Tab
      .state('characters', {
          url: "/characters",
          templateUrl: "partials/characters.html",
          controller: 'charactersController'
      })
  
    $urlRouterProvider.otherwise('/');
  });
  
  app.value('global', {
      characterID: '1'
  });
  
  //Blank/Home placeholder
  app.controller('appController', ['$scope', '$http', '$state', function ($scope, $http, $state) {
  
  }]);
  
  //Dragon List
  app.controller('dragonsController', ['$scope', '$http', '$ionicPopup', '$ionicActionSheet', '$state', '$ionicLoading', '$timeout', 'global', function ($scope, $http, $ionicPopup, $ionicActionSheet, $state, $ionicLoading, $timeout, global) {
  
      $ionicLoading.show({
          content: 'Loading',
          animation: 'fade-in',
          showBackdrop: true,
          maxWidth: 200,
          showDelay: 0
      });
  
      $timeout(function () {
          $ionicLoading.hide();
          $http.get('dragons.json')
          .success(function(data) {
              $scope.contents = data;
          });
      }, 1500);
  
      $http.get('progress.json')
      .success(function(data) {
          $scope.progress = data;
  
          characterIdToFind = global.characterID;
          var foundCharacter = null;
          for (var i in data) {
              var character = data[i];
              if (character.character_id == characterIdToFind) {
                  foundCharacter = character;
                  break;
              }
          }
  
          if (foundCharacter === null) {
              alert('oh no! didnt find a character!');
          }
      });
      $scope.zonefilter = {};
      $scope.sharePrompt = function() {
          $scope.data = {}
          var myPopup = $ionicPopup.show({
              template: '&lt;input type="email" ng-model="data.searchUser"&gt;',
              title: 'Enter User Email',
              scope: $scope,
              buttons: [
              { text: 'Cancel' },
              {text: '&lt;b&gt;Save&lt;/b&gt;',
              type: 'button-positive',
              onTap: function(e) {
                  if (!$scope.data.searchUser) {
                  $scope.showAlert();
                  console.log('No Content Input');
                  e.preventDefault();
              } else {
                  console.log('Input:', $scope.data.searchUser);
                  }
              }}]
          });
      };
      $scope.showAlert = function() {
          var alertPopup = $ionicPopup.alert({
              title: 'Error',
              template: 'Please enter a valid email address'
          });
          alertPopup.then(function(res) {
              console.log('Try again!');
          });
      };
      $scope.sortPrompt = function() {
          var hideSheet = $ionicActionSheet.show({
              buttons: [
                  {text: 'Colour'},
                  {text: 'Family' },
                  {text: 'Zone' }
              ],
              titleText: 'Select a category to sort by',
              cancelText: 'Cancel',
              cancel: function() {},
          buttonClicked: function(index) {
              console.log('BUTTON CLICKED', index);
              if(index == 0) {console.log('colour'); $state.go('dragonsColour');}
              if(index == 1) {console.log('family'); $state.go('dragonsFamily');}
              if(index == 2) {console.log('zone'); $state.go('dragonsZone');}
              return true;
          }
          });
      };
  }]);
  
  //Character
  app.controller('charactersController', ['$scope', '$http', 'global', function($scope, $http, global) {
      $http.get('characters.json')
      .success(function(data) {
          $scope.contents = data;
      });
          $scope.data = {
              characterSelection: global.characterID
          };
  
          $scope.selectCharacter = function(character) {
              global.characterID = character
              console.log(character);
          }
  }]);
  </code></pre>