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

这段时间在公司使用angularjs开发公司内部使用的系统, 经常遇到权限控制问题,动态数据中的按钮如何控制权限显示隐藏

1. 自定义directive:

 1 dirt.directive('onFinishRenderFilters',['$timeout',function($timeout){
 2     return {
 3         restrict:'A',
 4         link:function(scope){
 5             if (scope.$last === true) {
 6                 $timeout(function() {
 7                     scope.$emit('ngRepeatFinished');
 8                 });
 9             }
10         }
11     }
12 }]);

2. 使用ng-repeat动态循环出数据, 然后在我们需要监控的地方,加上该directive:

 1 <tbody>
 2   <tr ng-repeat="n in noticeListData" on-finish-render-filters>
 3     <td ng-bind="n.title"></td>
 4        <td ng-bind="n.noticetype"></td>
 5        <td ng-bind="n.district"></td>
 6        <td ng-bind="n.createTime"></td>
 7        <td ng-bind="n.createDepartment"></td>
 8        <td ng-bind="n.createUserName"></td>
 9    </tr>
10 </tbody>

 3. 最后在控制器中使用:

1 $scope.$on('ngRepeatFinished', function () {
2   var rightsRES = rightsActionHttp.rightsAction('kygjsc');
3    setTimeout(function(){
4      $('.'+rightsRES).remove();
5    },100);
6 });
原文地址:https://www.cnblogs.com/l000/p/7722360.html