1、当angular渲染完成后操作DOM树方法
//当数据渲染完毕
ngApp.directive('repeatFinish', function () {
return {
link: function (scope, element, attr) {
if (scope.$last == true) {
console.log('ng-repeat执行完毕')
//初始左菜单
$(".first-nav").eq([idxData.idx_mod1]).find("span").addClass('open')
$(".first-nav").eq([idxData.idx_mod1]).parent("li").addClass('open')
$(".first-nav").eq([idxData.idx_mod1]).next("ul").css("display", "block")
scope.$eval(attr.repeatFinish)
}
}
}
})
//当angular数据加载完成之后操作dom元素
$scope.renderFinish = function () {
console.log('渲染完之后的操作,操作jquery')
}
在循环标签上添加
<ul style="" class="second-list" >
<li class="second-item" repeat-finish="renderFinish()" ng-repeat="sub in super.children" > </li>
</ul>
2、angular循环套循环方法
<ul id="sys-sidebar-menu" class="page-sidebar-menu" data-keep-expanded="false" data-auto-scroll="true" data-slide-speed="200">
<li ng-repeat="item in modules" >
<a class="first-nav" href="javascript:;" >
<span class="icon-arrow" ></span>
<span class="title">{{::item.name}}</span>
</a>
<ul style="font-size:14px;color:#333" class="second-bar" >
<li role="presentation" ng-repeat="items in item.children track by $index" >
</li>
</ul>
</li>
</ul>