0

I have a simple Angular/Ionic View that I am binding a model to. Below is an example of the controller:

.controller('LocationDetailsCtrl',function($scope,$http,$stateParams,$local    storage,$log,Locations){

   var locationId = $stateParams.locationId;

   Locations.setCurrent(locationId);

   var model = {
       location:null
   };

   Locations.getById(locationId)
     .then(function(location){
       $scope.model.location = location;
     },function(error){
       $log.error(error);
   });

   $scope.model = model;
}

I am being the property $scope.model.location.name to the header title on the view.

This looks like the following

<ion-view view-title="{{model.location.name}}">
   <ion-content>

   ... other model binding stuff here works fine

   </ion-content>
</ion-view>

The problem I am running into is that when the view loads the first time, everything loads fine except the header binding. Then I can go to another view, and come back to this iew and the title is bound correctly the model on my scope.

Here are screenshots

First time the view loads..

enter image description here

After I navigate to another view and come back

enter image description here

Not sure why it wouldn't bind the first time when all the other $scope.model.location.XXXX properties bind correctly and update in the view.

TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

1 Answers1

0

Use

if (!$scope.$$phase) $scope.$apply()

after you after

$scope.model.location = location;

Mandeep Singh
  • 857
  • 8
  • 13