Home  >  Article  >  Web Front-end  >  Issues related to listening to ng-repeat rendering in AngularJS

Issues related to listening to ng-repeat rendering in AngularJS

亚连
亚连Original
2018-06-11 17:00:361410browse

This article mainly introduces two methods for AngularJS to monitor the completion of ng-repeat rendering, and analyzes the related operating techniques of AngularJS based on custom instructions and broadcast events to implement the monitoring function based on examples. Friends in need can refer to the following

The examples in this article describe two methods for AngularJS to monitor the completion of ng-repeat rendering. Share it with everyone for your reference, the details are as follows:

There are two methods to monitor the completion of ng-repeat rendering

1. The most practical method:

<ul class="pprt_content">
    <li ng-repeat="src in imageHotList track by $index" ng-click=&#39;goGoodsDet(src.goodsId,src.merchId)&#39; on-finish-render-filters="completeRepeat">
      <img ng-src="{{productUrl}}{{src.imageName}}">
    </li>
</ul>

Corresponding scope controller:

$scope.completeRepeate= function(){
alert(&#39;1&#39;)
}

Custom instruction directive:

var app = angular.moduler(&#39;myApp&#39;,[]);
app.directive(&#39;onFinishRenderFilters&#39;, [&#39;$timeout&#39;, function ($timeout) {
    return {
      restrict: &#39;A&#39;,
      link: function(scope,element,attr) {
        if (scope.$last === true) {
          var finishFunc=scope.$parent[attr.onFinishRenderFilters];
          if(finishFunc)
          {
            finishFunc();
          }
        }
      }
    };
}])

2. Use broadcast events

/*
* Controller文件中的代码
* Setup general page controller
*/
MetronicApp.controller(&#39;simpleManageController&#39;, [&#39;$rootScope&#39;,
&#39;$scope&#39;, &#39;settings&#39;,&#39;$http&#39;, function($rootScope, $scope, settings,$http) {
  $scope.$on(&#39;ngRepeatFinished&#39;, function (ngRepeatFinishedEvent) {
    //下面是在table render完成后执行的js
    FormEditable.init();
    Metronic.stopPageLoading();
    $(".simpleTab").show();
  });
});
MetronicApp.directive(&#39;onFinishRenderFilters&#39;, function ($timeout) {
  return {
    restrict: &#39;A&#39;,
    link: function(scope,element,attr) {
      if (scope.$last === true) {
        $timeout(function() {
          scope.$emit(&#39;ngRepeatFinished&#39;);
        });
      }
    }
  };
});

HTML

<!--HTML页面的代码,添加标签onFinishRenderFilters(格式有变):on-finish-render-filters-->
 <tr style="display: none" class="simpleTab" ng-repeat="simpleProduct in simpleProducts"
   on-finish-render-filters>
     <td>
       {{simpleProduct.productNo}}
     </td>
</tr>

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to use the global prompt box component in vue?

How to use ElementRef application in Angular4

How to use cli request proxy and project packaging issues in vue

Use webpack template in vue-cli to solve project construction and packaging path problems

Bus global event center in vue (detailed tutorial)

The above is the detailed content of Issues related to listening to ng-repeat rendering in AngularJS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn