Using the same array of objects in multiple places within HTML calls a custom filter multiple times though the filter is applied only once.
JS:
function MyController($scope){
$scope.addresses = [{obj1},{obj2},{obj3}];
}
HTML
<html>
<body>
<ul id="one">
<li ng-repeat="address in addressess ">{{address.name}}</li>
</ul>
<ul id="two">
<li ng-repeat="address in addressess ">{{address.name}}</li>
</ul>
<ul id="three">
<li ng-repeat="address in addressess | customFilter">{{address.name}}</li>
</ul>
</body>
</html>
- I have a controller with a property assigned an array of objects.
- I'm using the same object in the html in multiple places.
- In one of the places in the html, i apply a filter to show only specific set of values.
- The filter code gets called for all the iterations used in the html page.
- In the above scenario the customFilter got called thrice as i've used the addresses collection in three different places within the html but the filter is called only once under the element id 'three'
Hi, A filter should be a pure function that may end up being called multiple times, that said, in this specific case I would expect that the filter gets called twice and in all cases only for the last ng-repeat. Can you please create a plunker that shows this issue?
@sjselvan I agree with @lgalfaso , putting your code in plunker shows exactly 2 calls to a custom filter, as expected: http://plnkr.co/edit/SZuSXZLRwRvasGyE72XZ?p=preview
I guess something else is going in your code but it is impossible to say more without a minimal, live reproduce scenario. I'm going to close this issue for now as it is not actionable as-is. I would be happy to re-open if you've got more info.
i'm unable to replicate the issue. will update you folks, if i see it again.