[英]ngClass binding not updating via directive communication
我想嵌套兩個指令,並且inner directive
具有綁定到函數的ng-class
,該函數從內部和外部范圍獲取范圍屬性並返回布爾值
這是HTML:
<ul my-toolbar disabled-when="myCtrl.isProcessing" >
<li my-action-button action="myCtrl.action()" disable-when="myCtrl.isSad()" />
</ul>
這是我的外部指令:
myApp.directive("myToolbar", function() {
return {
restrict: 'A',
scope: {
disabled: '=disabledWhen'
},
transclude: true,
controller: function($scope) {
this.isDisabled = function() {
return $scope.disabled;
}
}
};
});
這是我的內部指令:
myApp.directive("myActionButton", function() {
return {
restrict: 'A',
scope: {
action: '&',
disabled: '=disabledWhen'
},
replace: true,
template: "<li ng-class='{disabled: isDisabled()}'><a ng-click='isDisabled() || action()' /></li>",
link: function(scope, elem, attrs, toolbarCtrl) {
scope.isDisabled = function() {
return toolbarCtrl.isDisabled() || scope.disabled;
};
}
};
});
現在的問題是, ng-class='{disabled: isDisabled()}'
綁定在開始時初始化一次,但是在myCtrl.isProcessing
更改時不會更新!
有人可以解釋為什么嗎? 以及如何在不更改設計的情況下解決此問題?
@Jonathan根據要求,我將我的angular code
放在小提琴中,並且(這部分現在讓我很惱火)可以正常工作!
http://jsfiddle.net/shantanusinghal/ST3kH/1/
現在,我將回頭看看為什么在我的生產代碼中它對我不起作用! *困惑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.