AngularJs中,如何在ng-repeat完成之后,执行Js脚本
生活随笔
收集整理的這篇文章主要介紹了
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> //在需要監控的地方,加上該directivehello world!</li> <ul> </body>
<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> //在需要監控的地方,加上該directivehello world!</li> <ul> </body>
轉載于:https://www.cnblogs.com/leyi/p/5055320.html
總結
以上是生活随笔為你收集整理的AngularJs中,如何在ng-repeat完成之后,执行Js脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 根据上边栏和下边栏的高度进行布局
- 下一篇: 链表——实现单链表的反转