Reputation: 8047
I have a selectize dropdown
<selectize config="mySelectizeConfig" options="getAvailableObjects(id)""></selectize>
On my controller when I return an array works fine
$scope.getAvailableObjects=function(id) {
return $scope.available_objects[id]
}
But when I am trying to filter the array
$scope.getAvailableObjects=function(id) {
var result = [];
result = $scope.available_objects[id].filter(function(object) {
return object.is_active;
});
return result;
}
Gives me an 'Error: 10 $digest() iterations reached' How can I troubleshoot that ?
I am getting the same error when I am trying to filter the array on the view.
options="available_objects[id] | filter: {'is_active':true}"
Upvotes: 0
Views: 60
Reputation: 13488
It is because, Array.prototype.filter
method as well as | filter : {'is_active':true}
will always return new array, so $digest() iterations reached, even though returning arrays look equally. You can fix it by caching them:
var cache = {};
$scope.getAvailableObjects = function(id) {
return cache[id] = cache[id] || $scope.available_objects[id].filter(function(object) {
return object.is_active;
});
}
If $scope.available_objects
will be changed, you can reset cache = {}
;
Upvotes: 0