如何在指令中设置 ng-disabled [英] How to set ng-disabled inside directive
本文介绍了如何在指令中设置 ng-disabled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的指令有
link: function ($scope, $elm, $attrs) {
var status = $scope.item.status
if (status) {
var statusName = status.name,
item = $scope.item;
if (statusName === 'USED') {
$attrs.$set('ng-disabled', true); // this doesn't work
} else {
$elm.attr('ng-disabled', false);
}
}
}
所以,我的问题是:
如何使用此指令将 ng-disabled 应用到元素?
How to apply ng-disabled to element with this directive?
推荐答案
您可以将 ng-disabled
设置为范围变量,例如:
You would set ng-disabled
to a scope variable, ex:
<input ng-disabled="isDisabled" />
然后在你的指令中你可以设置那个变量:
And then inside your directive you can set that variable:
$scope.isDisabled = true;
这篇关于如何在指令中设置 ng-disabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文