之前用了ng-repeat写了一个渲染时间进度条的需求,但是angular和vue不同,在angualr中通过ng-repeat生成的dom元素无论我怎么操作JS都获取不到,后来发现:angular渲染dom完成了,才能对想要的元素进行操作!
具体操作如下:
JS文件:
app.directive('onFinishRenderFilters', function ($timeout) {
return {
restrict: 'A',
link: function(scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
};
});
$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
//此处为具体方法(获取dom操作)
});
html文件
<div ng-repeat="(i,item) in list" on-finish-render-filters>
//具体页面html
</div>