这篇文章给大家分享的是有关AngularJS如何监听ng-repeat渲染完成的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
监听ng-repeat渲染完成有两种方法
一、最实用的方法:
<ul class="pprt_content">
<li ng-repeat="src in imageHotList track by $index" ng-click='goGoodsDet(src.goodsId,src.merchId)' on-finish-render-filters="completeRepeat">
<img ng-src="{{productUrl}}{{src.imageName}}">
</li>
</ul>
对应作用域controller:
$scope.completeRepeate= function(){
alert('1')
}
自定义指令directive:
var app = angular.moduler('myApp',[]);
app.directive('onFinishRenderFilters', ['$timeout', function ($timeout) {
return {
restrict: 'A',
link: function(scope,element,attr) {
if (scope.$last === true) {
var finishFunc=scope.$parent[attr.onFinishRenderFilters];
if(finishFunc)
{
finishFunc();
}
}
}
};
}])
二、使用广播事件
MetronicApp.controller('simpleManageController', ['$rootScope',
'$scope', 'settings','$http', function($rootScope, $scope, settings,$http) {
$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
//下面是在table render完成后执行的js
FormEditable.init();
Metronic.stopPageLoading();
$(".simpleTab").show();
});
});
MetronicApp.directive('onFinishRenderFilters', function ($timeout) {
return {
restrict: 'A',
link: function(scope,element,attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
};
});
HTML
<!--HTML页面的代码,添加标签onFinishRenderFilters(格式有变):on-finish-render-filters-->
<tr class="simpleTab" ng-repeat="simpleProduct in simpleProducts"
on-finish-render-filters>
<td>
{{simpleProduct.productNo}}
</td>
</tr>
感谢各位的阅读!关于“AngularJS如何监听ng-repeat渲染完成”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!