Indeed, you should use directives, and there is no event tied to the end of a ng-Repeat loop (as each element is constructed individually, and has it's own event).(实际上,你应该使用指令,并且没有事件与ng-Repeat循环的结束相关联(因为每个元素是单独构造的,并且具有它自己的事件)。)
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.(但是a)使用指令可能就是你所需要的全部b)有一些ng-Repeat特定属性可用于制作你的“on ngRepeat finished”事件。)
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.(具体来说,如果您只想在整个表中设置样式/添加事件,则可以在包含所有ngRepeat元素的指令中使用。)
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.(另一方面,如果要专门处理每个元素,可以在ngRepeat中使用指令,它将在创建后对每个元素起作用。)
Then, there are the $index
, $first
, $middle
and $last
properties you can use to trigger events.(然后,您可以使用$index
, $first
, $middle
和$last
属性来触发事件。)
So for this HTML:(对于这个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');
};
});
See it in action in this Plunker .(在此Plunker中查看它的实际应用 。)
Hope it helps!(希望能帮助到你!) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…