1

I have two arrays (scope variables) whose values are getting updated dynamically, but in the HTML when I am trying to print their values, the view is not taking the updated ones.

<div>
    <!-- array printing -->
    <span ng-repeat="var in array track by $index">{{var}}</span>
</div>
<div>
    <!-- array -->
    <span ng-repeat="var in array2 track by $index">{{var}}</span>
</div>

When I am printing the values in the console log, the array is changing but its changes are not getting reflected in the page.

controller.js

$scope.update = function() {

    $scope.array.push(box); 

    // inside an ajax call
    var index = $scope.array.indexOf(box);

    if(index > -1) {
        $scope.array.splice(index,1);
        console.log("index "+index);
    }  
}
6
  • 1
    what is your updating function ? Commented Jun 12, 2015 at 7:41
  • On what action array gets updated? Can u pls provide controller js? Commented Jun 12, 2015 at 7:41
  • can you provide a plunker or fiddle ? Commented Jun 12, 2015 at 8:48
  • in second array, wtf is {{request}} ? :) should be {{var}} Commented Jun 12, 2015 at 8:55
  • Sorry, that was {{var}} Commented Jun 12, 2015 at 9:12

1 Answer 1

1

It seems that your Ajax call is not being called by AngularJS. Maybe you're using jQuery?

In this case, try using $scope.$apply(); after the end of the Ajax callback function. It will verify any changes and update your view variables.

You can read more about $apply here and here.

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

1 Comment

Yeah it worked. Thanks :) I had to call the digest loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.