简体   繁体   English

如何使用ng-repeat在AngularJS中完成DOM渲染

[英]How to know DOM rendering is completed in AngularJS using ng-repeat

I want to raise an alert or message when my html dom has completed rendering using angularjs with the multiple ng-repeat. 当我的html dom使用带有多个ng-repeat的angularjs完成渲染时,我想发出警报或消息。

HTML Code: HTML代码:

       <body>
            <div ng-controller="Ctrl">
               <div ng-repeat="thing in things" my-post-repeat-directive>                                    
                        thing {{thing}}
                  </div>
                  <div ng-show="complete">Complete {{complete}}</div>
            </div>
      </body>

JS Code JS代码

       function Ctrl($scope) {
        $scope.complete = false;
          $scope.doComplete = function() {
              $scope.complete = true;
           }

         $scope.things = [
                    'A', 'B', 'C'
                    ];
              }

          angular.module('myApp', [])
          .directive('myPostRepeatDirective', function() {
            return function(scope, element, attrs) {
           if (scope.$last) {
            scope.$eval('doComplete()');
              }
         };
     });

AngularJS has LIFECYCLE HOOKS as AngularJS具有LIFECYCLE HOOKS作为

$postLink(() => {
   yours alert
})

$postLink() - Called after this controller's element and its children have been linked. $ postLink()-在链接此控制器的元素及其子元素之后调用。 Similar to the post-link function this hook can be used to set up DOM event handlers and do direct DOM manipulation 与后链接功能类似,此钩子可用于设置DOM事件处理程序并直接进行DOM操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM