angularJs监听器的实现及排坑
程序员文章站
2022-05-01 12:26:51
...
var app = angular.module('roleManage', []);
app.directive('onFinishRenderFilters', ['$timeout',
function($timeout) {
console.log('开启监听');
return {
restrict: 'A',
link: function(scope, element, attr) {
if(scope.$last == true) {
console.log('监听成功');
scope.openClose();
scope.selected();
}
}
};
}
])
<ul class="tree">
<li ng-repeat="menu in permissionList" on-finish-render-filters><label>{{menu.oneLevel.name}}</label>
<ul style="display: block;">
<li class="active" ng-repeat="menu2 in menu.twoLevelList"><label>{{menu2.name}}</label>
</li>
</ul>
</li>
</ul>
当在同一个页面中菜单ul用了两次,并且遍历list相同,当list对象变化时,监听器执行两次。
上一篇: flex引起height:100%失效
下一篇: soul网关源码学习路径(一)
推荐阅读