【发布时间】:2015-02-23 08:08:27
【问题描述】:
根据 angulars 文档,“父”的发布链接功能将仅在子指令的发布链接功能执行后执行。
但是,如果是以下代码,为什么我需要触发“emit”事件来通知 ng-repeat 已完成。理想情况下,它应该自动运行而不需要发出事件。
<div ng-controller="Ctrl" my-main-directive>
<div ng-repeat="thing in things" my-repeat-directive>
thing {{thing}}
</div>
</div>
angular.module('myApp', [])
.directive('myRepeatDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('color','blue');
if (scope.$last){
window.alert("im the last!");
}
};
})
.directive('myMainDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('border','5px solid red');
};
});
我无法掌握指令执行顺序的概念。我心中对上述指令的疑问总是让我感到困惑。请帮助我理解这一点。先谢谢了!!!
【问题讨论】:
-
如果您只关心颜色或其他 CSS 样式,那么为什么不首先使用 CSS 样式表呢?类似
element:last-child {color: blue;}
标签: angularjs angularjs-directive