我发现,如果创建了我添加到正在创建ng-repeat的元素的另一个指令,则会针对创建的每个元素通知它。然后,我可以简单地$
emit一个事件,其父指令可以监听。在这一点上,它可以执行到那里重复元素的链接。这尤其适用于dom中的多个ng-
repeat,因为我可以按事件类型将它们分开,然后将事件类型传递给新指令。
这是我的指令:
App.directive("onRepeatDone", function() { return { restrict: 'A', link: function($scope, element, attributes ) { $scope.$emit(attributes["onRepeatDone"] || "repeat_done", element); } }});这是模板中该新指令的用法:
<ul> <li on-repeat-done="domain_done" ng-repeat="domain in domains">...</li></ul>
然后在父指令中,我可以执行以下操作:
link: function( $scope, element, attributes ) { $scope.$on('domain_done', function( domainElement ) { domainElement.find('.someElementInsideARepeatedElement').click(...); } );}


