AngularJS listens to two methods after ng-repeat rendering is completed, angularjsng-repeat

Source: Internet
Author: User

AngularJS listens to two methods after ng-repeat rendering is completed, angularjsng-repeat

This article describes two ways for AngularJS to listen for ng-repeat rendering. We will share this with you for your reference. The details are as follows:

There are two ways to listen for ng-repeat rendering completion

I. Most practical methods:

<ul class="pprt_content">    <li ng-repeat="src in imageHotList track by $index" ng-click='goGoodsDet(src.goodsId,src.merchId)' on-finish-render-filters="completeRepeat">          </li></ul>

Corresponding scope controller:

$scope.completeRepeate= function(){alert('1')}

Custom directive:

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

Ii. Use broadcast events

/** The code in the Controller file * Setup general page controller */MetronicApp. controller ('simplemanagecontroller', ['$ rootScope', '$ scope', 'settings', '$ http', function ($ rootScope, $ scope, settings, $ http) {$ scope. $ on ('ngrepeatfinished', function (ngRepeatFinishedEvent) {// below is the js FormEditable executed after table render is complete. init (); Metronic. stopPageLoading (); $ (". simpleTab "). show () ;}); MetronicApp. directive ('onfinishrenderfilters ', function ($ timeout) {return {restrict: 'A', link: function (scope, element, attr) {if (scope. $ last = true) {$ timeout (function () {scope. $ emit ('ngrepeatfinished ');});}}};});

HTML

<! -- Add the onFinishRenderFilters tag to the Code on the HTML page (the format has changed): on-finish-render-filters --> <tr style = "display: none "class =" simpleTab "ng-repeat =" simpleProduct in simpleProducts "on-finish-render-filters> <td >{{ simpleProduct. productNo }}</td> </tr>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.