Tuesday, August 16, 2016

 $digest already in progress when calling $scope.$apply() in AngularJS

I was getting this error during i made call to a third-party library to access data on their servers, so I can't take advantage of $http, nor do I want to since I would have to rewrite their library to use $http.

$http.jsonp(http://api.myapifilms.com/imdb/idIMDB?title=” “).success(function (response) {
             alert($scope.searchByTitle);           
             $scope.movies = response.data.movies;

  $scope.$digest();

// If i write above $digest method directly i thrown me an error though if i put it into little diff form than it works fine.
$timeout(function () {
                   $scope.$digest();
             }, 100);

 

Reason behind this is ,$timeout function takes this execution as async request.

Thanks

0 comments :

Post a Comment