当检测到一个自定义过滤器在AngularJS已完成 [英] Detect when a custom filter has completed in AngularJS
问题描述
我有一个自定义过滤器的功能,我呼吁NG重复指令:
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>
这显然是打我assetFilter功能在APPLIST每个应用程序。当过滤完成后,我想运行其他的功能。
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?
更新
根据指着我的反应对其他的答案,我可以进一步明确了一点。
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:
- 它将按预期工作当页面首次呈现并填充列表 - 检测到最后一个项目
- 当我的过滤功能被触发,项目从列表中删除,该指令的处理程序是打不到的。
- 当相同的项目重新添加到列表中,但他们没有在列表的最后一个项目,该指令被击中,但只适用于正在添加的项背,并没有项目与范围。$持续如此。
希望这有助于澄清。
推荐答案
NG-重复
为每个重复元素的范围。此范围包括 $第一个
和 $最后
,所以你可以添加检查这些指令
ng-repeat
creates a scope for each repeated element. This scope includes $first
and $last
so you can add a directive that checks for these
HTML
<div ng-repeat="item in items" check-last>
指令:
app.directive('checkLast',function(){
return{
restrict:'A',
link:function(scope,elem,attrs){
if(scope.$last){
/* repeater done code*/
}
}
}
})
<大骨节病> 演示 大骨节病>
这篇关于当检测到一个自定义过滤器在AngularJS已完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!