I'm using Angular and what I'm trying to do is pass a filtered collection to a directive.
My view looks like this:
<h1>Filtered Collection (no directive)</h1>
<ul>
<li ng-repeat="person in filteredPeople = (people | filter: { isChecked: true })">
{{ person.name }}
</li>
</ul>
The data that I'm passing is just a simple array of objects:
$scope.people = [
{
name: "George",
isChecked: false
},
{
name: "Jane",
isChecked: false
},
{
name: "Peter",
isChecked: true
}
];
Everything works fine so far. But when I try to put the HTML above in a directive the app crashes.
Directive:
myApp.directive('filterPeople', function () {
return {
restrict: 'A',
template: '<h1>Filtered Collection (directive)</h1>' +
'<ul>' +
'<li ng-repeat="item in collection">{{ item.name }}</li>' +
'</ul>',
scope: {
collection: '=collection'
}
}
});
View:
<div filter-people collection="filteredPeople"></div>
The error that I get:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations
P.S. I've uploaded my example in Plunker and everything seems to work there. I've checked whether the code in my app is the same and it is. So, why is this happening? My code runs on Plunker but doesn't in my real app.