angular 获取ng-repeat完成状态 $last

时间:2023-03-09 07:02:44
angular 获取ng-repeat完成状态 $last

$index $first $middle $last $odd $even

html

<ul>
<li ng-repeat="item in data" repeat-finish="renderFinish()">{{item.str}}</li>
</ul>

指令

app.directive('repeatFinish',function(){
return {
link: function(scope,element,attr){
console.log(scope.$index)
if(scope.$last == true){
console.log('ng-repeat执行完毕')
scope.$eval( attr.repeatFinish )
}
}
}
})

ctrl里面

//controller里对应的处理函数
$scope.renderFinish = function(){
console.log('渲染完之后的操作')
}