0

I'm fetching the data using $http.get() and passing it as argument to a custom filter to get the filterd data. But it is giving an error: $digest already in progress.

Does anyone know how to avoid this error or achieve the same thing but a different way?

var map=angular.module('map', [])
.controller('mapCtrl', function ($scope,$filter,$http) {
 $http.get('./json/integrated.json').success(function(data) {
     $scope.sitesInfo = data;
   });
 var filteritems= $filter('applySfotwareFilter')($scope.sitesInfo);
  
  });
Aditya
  • 59
  • 6

1 Answers1

1

I think you should place

var filteritems= $filter('applySfotwareFilter')($scope.sitesInfo);

inside your success function;

What happens is the filtering starts before your data is ready.

Manube
  • 5,110
  • 3
  • 35
  • 59
  • Even better might be to move the filter to the UI where it is require. usage of $filter in the controller always seems a little icky to me – Abhinav Gujjar Feb 20 '15 at 11:54
  • true, it looks neater in the UI. However, it can be more efficient to place the filter in the controller, rather than having it slow down the application in a long ng-repeat. But that's another debate altogether... – Manube Feb 20 '15 at 12:03
  • @Aditya if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Manube Feb 24 '15 at 05:19