0

I have a list that I am using ng-repeat and one-time binding because there is no need for me to update once I have the data.

I was hoping that I could use one-time binding and force a digest, but I get the common error that a $digest is already being processed or whatever it is.

My code looks like the following

$scope.$on(IonicEvents.beforeEnter, function() {
    Locations.getAllLocations()
        .then(function(allLocations) {
            $scope.model.locations = allLocations;
            //I have tried $scope.$digest()..
            //also $scope.$apply()...
        }, function(error) {
            $log.error('Error retrieving locations');
        })
});

My ng-repeat in my template looks like the following:

<ion-item class="item" ng-repeat="location in ::model.locations">
    <div class="row">
        <div class="col">
            <p>{{::location.name}}</p>
        </div>
    </div>
</ion-item>

Any ideas, or am I completely off-track?

Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

2 Answers2

0

I think First you may check if(!$scope.$$phase) then apply your proccess

$scope.$on(IonicEvents.beforeEnter, function() {
if(!$scope.$$phase) {
    Locations.getAllLocations()
        .then(function(allLocations) {
            $scope.model.locations = allLocations;
            //I have tried $scope.$digest()..
            //also $scope.$apply()...

        }, function(error) {
            $log.error('Error retrieving locations');
        })
   }
});
Nadimul De Cj
  • 484
  • 4
  • 16
0

Yes I think you are off-track.

My idea for your particular situation would be using a clone object (with no reference to the main object) once they are retrieved from Locations.getAllLocations() using

$scope.clonedLocationObj = angular.copy($scope.model.locations);

and render this object to your view so that it won't effect your main object.

As far as one way binding is concerned, Angular doesn't let you change the one time binded model again because when we declare a value such as {{ ::foo }} inside the DOM, once this foo value becomes defined, Angular will render it, unbind it from the watchers and thus reduce the volume of bindings inside the $digest loop. Simple! angular one time binding syntax article

Hope it helps.

M. Junaid Salaat
  • 3,765
  • 1
  • 23
  • 25