Reputation: 237
in my program iam displaying a list of images. And then iam filtering it with a tag name. So here is my filter.
app.filter('myFilter', function()
{
var filtered = [];
return (function(items, text)
{
if (text === undefined)
{
return items;
}
else
{
angular.forEach(items, function(value, key)
{
var sample = value.tag;
angular.forEach(sample, function(value1, key)
{
if (text === value1)
{
filtered.push(value);
}
});
});
}
return filtered;
})
});
And the html is:
<ul>
<li ng-repeat="x in outputphotos| myFilter:text">
<a href="#displayimage/{{x.imageId}}"><img ng-src="{{x.url}}"></a>
</li>
</ul>
And in the output it will filter one time. But if second time i enter a tag then it wont filter. And shows an error in console 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [] Duplicates in a repeater are not allowed. Repeater: x in outputphotos| myFilter:text key: object:004
I dont know how to change this error.
Upvotes: 3
Views: 11273
Reputation: 1
Try this in Angular.js:
function $RootScopeProvider() { var TTL = 10; // Increase the value of TTL, default value is 10
Upvotes: 0
Reputation: 42669
Let me take a wild guess, move your filtered array declaration var filtered = [];
inside the return statement, something like
return (function(items, text)
{
var filtered = [];
I believe you are not clearing the old filter and try to update the filter array which is triggering the watch again. You repeat is bound to filtered
array.
Upvotes: 4