NG-重复完成事件 [英] ng-repeat finish event
问题描述
我想打电话给一些jQuery函数表目标股利。该表中填充了 NG-重复
。
I want to call some jQuery function targeting div with table. That table is populated with ng-repeat
.
当我把它放在
$(document).ready()
我没有结果。
此外
$scope.$on('$viewContentLoaded', myFunc);
于事无补。
有什么办法NG-重复的人口完成后要执行的功能吧?我读过的有关建议使用自定义指令
,但我不知道如何与NG重复我的div使用它...
Is there any way to execute function right after ng-repeat population completes? I've read an advice about using custom directive
, but I have no clue how to use it with ng-repeat and my div...
推荐答案
事实上,你应该使用的指令,而且没有事件绑定到NG-重复循环结束(因为每个元素都单独构成,有它自己的事件)。但是,使用指令可能是你所需要的)和b)有你可以用它来作一些NG-重复特定属性的关于ngRepeat完成事件。
Indeed, you should use directives, and there no event tied to the end of a ng-Repeat loop (as each element is constructed individually, and has it's own event). But a) using directives might be all you need and b) there are a few ng-Repeat specific properties you can use to make your "on ngRepeat finished" event.
特别是,如果你想要的是款式/事件添加到整个表,你可以这样做用,它包括所有ngRepeat元素的指令。在另一方面,如果你想专门针对每一个元素,可以在ngRepeat内使用一个指令,它会采取行动的每个元素上,在创建后。
Specifically, if all you want is to style/add events to the whole of the table, you can do so using in a directive that encompasses all the ngRepeat elements. On the other hand, if you want to address each element specifically, you can use a directive within the ngRepeat, and it will act on each element, after it is created.
那么,还有 $指数
, $第一个
, $中间
和 $最后
属性,你可以用它来触发事件。因此,对于这个HTML:
Then, there are the $index
, $first
, $middle
and $last
properties you can use to trigger events. So for this HTML:
<div ng-controller="Ctrl" my-main-directive>
<div ng-repeat="thing in things" my-repeat-directive>
thing {{thing}}
</div>
</div>
您可以使用像这样的指令:
You can use directives like so:
angular.module('myApp', [])
.directive('myRepeatDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('color','blue');
if (scope.$last){
window.alert("im the last!");
}
};
})
.directive('myMainDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('border','5px solid red');
};
});
看到它在行动在这个 Plunker 。希望它能帮助!
这篇关于NG-重复完成事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!