我往数组中push
一条数据,页面上不就执行循环吗ng-repeat
,我想让循环完事之后,触发一个点击事件,点击最后一条,thats all
给我你的怀抱2017-05-15 16:56:43
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() {
// 做你爱做的事
}
}
迷茫2017-05-15 16:56:43
Use ng-class to implement, this is my solution:
Click on the preview to see the effect directly: http://codepen.io/liekkas/pen/JdgLzJ