zoukankan      html  css  js  c++  java
  • AngularJs中,如何在ng-repeat完成之后,执行Js脚本

      //ng-repeat生成4个li,生成后再执行自定义方法fn在每个li后加一根横线
    <script> var myapp=angular.module('myapp',[]); myapp.directive('onFinishRenderFilters', function ($timeout) { return { restrict: 'A', link: function(scope, element, attr) { if (scope.$last === true) { $timeout(function() { scope.$emit('ngRepeatFinished');//注册一个事件 }); } } }; }).controller('test',function($scope){ $scope.fn=function(){ $('.item').append('<hr/>') } $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {//监听事件 //下面是在li render完成后执行的js $scope.fn()
    })
    }) </script> <body ng-app="myapp" ng-controller="test"> <ul class="list" ng-init="aa=[1,2,3,4]"> <li class="item" ng-repeat="x in aa" on-finish-render-filters> //在需要监控的地方,加上该directive hello world! </li> <ul> </body>

      

  • 相关阅读:
    gdbinit理解
    debug套路
    node 版本升级
    工作方式
    vscode 插件编写
    函数闭包与装饰器
    高阶函数与递归
    函数嵌套及作用域
    函数
    文件处理
  • 原文地址:https://www.cnblogs.com/leyi/p/5055320.html
Copyright © 2011-2022 走看看