AngularJs中,如何在数据加载完成后,执行Js脚本

1、自定义服务

app. directive( 'onFinishRenderFilters', function ( $timeout) {
return {
restrict: 'A',
link : function ( scope, element, attr) {
if ( scope. $last === true) {
$timeout( function () {
scope. $emit( 'ngRepeatFinished');
});
}
}
};
});

2、html  使用ng-repeat循环渲染数据 然后在监控的地方添加 定义好的

< tbody >
< tr ng-repeat= "item in itemArr" on-finish-render-filters >
< td ng-bind= "item.title" > td >
< td ng-bind= "item.noticetype" > td >
< td ng-bind= "item.district" > td >
< td ng-bind= "item.createTime" > td >
< td ng-bind= "item.createDepartment" > td >
< td ng-bind= "item.createUserName" > td >
tr >
tbody >

3、最后在控制器中使用

$scope. $on( 'ngRepeatFinished', function ( ngRepeatFinishedEvent) {
//something...
});

你可能感兴趣的:(AngularJs中,如何在数据加载完成后,执行Js脚本)