我需要在ng-repeat完成更改dom后更新特定元素的样式。这是我的挑战。当我向模型添加项目时,我编写的用于执行ng-repeat工作的指令就可以了,但是当我从项目中删除一个对象时,该指令不会被调用。
我添加了一个功能,该功能可以随机推送和弹出列表中的数据。您会看到pop不会触发ng-repeat指令调用。无论如何要解决吗?
var module = angular.module('testApp', [])
.directive('onFinishRender', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
scope.$evalAsync(attr.onFinishRender);
}
}
}
});
Fiddle Link
最佳答案
你可以这样做:
<p ng-repeat="t in ta" on-finish-render="test()"
ng-init="myFunction($last, t)">{{t}}</p>
$scope.myFunction = function(isLast, item){
if(isLast)
console.log(item)
}
ng-init
是创建元素时运行的属性。$last
是布尔值,如果当前元素是true
中的最后一个元素,则为ng-repeat
。Updated Fiddle
关于javascript - 在ng-repeat完成工作后触发事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33958637/