This question already has an answer here:
- Calling a function when ng-repeat has finished 10 answers
- trigger function after ng-repeat 1 answer
I have a custom filter function I'm calling for ng-repeat directive:
<div ng-repeat="app in appVm.appList | filter:appVm.assetFilter">{{app.title}}</div>
This obviously hits my assetFilter function for each app in the appList. When filtering is complete, I want to run another function.
How can I detect when the filtering pass has completed?
Update
Based on responses pointing me towards other answers, I can clarify a bit further.
When I implement that solution with a custom directive and using the scope.$last, I observe the following:
- It works as expected when the page is first rendered and the list is populated - the last item is detected.
- When my filter function is triggered and items are removed from the list, the directive handler is not hit at all.
- When the same items are the added back into the list, but they're not the last items in the list, the directive is hit, but only for the items being added back in, and there is no item with a scope.$last of true.
Hope this helps to clarify.
ng-repeat
creates a scope for each repeated element. This scope includes$first
and$last
so you can add a directive that checks for theseHTML
Directive:
DEMO