angular.js - Can a function be executed after ng-repeat?
世界只因有你
世界只因有你 2017-05-15 16:54:43
0
2
573

I add a piece of data to the arraypush, won’t the loop be executed on the pageng-repeat, I want to trigger a click event after the loop is completed, click on the last item, thats all

世界只因有你
世界只因有你

reply all(2)
给我你的怀抱

If you ask me, it would be more refreshing to get it done once and for all:

angular.module('demo', [])

.directive('repeatDone', function() {
    return {
        link: function(scope, element, attrs) {
            if (scope.$last) {                   // 这个判断意味着最后一个 OK
                scope.$eval(attrs.repeatDone)    // 执行绑定的表达式
            }
        }
    }
})

Usage:

<!-- 模版 -->
<p ng-repeat="..." repeat-done="doSomething()"></p>
// 控制器
function SomeController(scope) {
    scope.doSomething = function() {
        // 做你爱做的事
    }
}
迷茫

Use ng-class to implement, this is my solution:

Click on the preview to see the effect directly: http://codepen.io/liekkas/pen/JdgLzJ

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template