Javascript 如何从 AngularJS 输入中禁用我的复选框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29356347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I disable my checkbox from AngularJS input?
提问by Christine268
<div ng-repeat="x in spaceutilization">
<input type="checkbox" name="{{x.filenumber}}" id="{{x.id}}" class = "pdffiles" value="101SP{{x.initials}}.dwg" /><label for="{{x.id}}"><button type = "button" class = "btn btn-primary btn-sm hidden-sm hidden-xs"> PDF</button></label><br />
</div>
I need to be able to add something to this snippet that disables the input checkbox based on another AngularJS input such as {{x.status}}. I tried simply doing:
我需要能够向此代码段添加一些内容,以禁用基于另一个 AngularJS 输入(例如 {{x.status}})的输入复选框。我试着简单地做:
<input type="checkbox" name="{{x.filenumber}}" id="{{x.id}}" class = "pdffiles" value="101SP{{x.initials}}.dwg" {{x.status}} />
Where status:'disabled'but that gave an output of
哪里status:'disabled'但是这给出了输出
{{x.status}}=""
within the input element...which I don't understand why at all. But it seemed like the simplest route.
在输入元素中......我根本不明白为什么。但这似乎是最简单的路线。
回答by Pankaj Parkar
You need to use ng-disabled="expression"directive, on basic of expression evaluation value it add disabled attribute to that element.Also for better attribute values evaluation you could use ng-attrdirective
您需要使用ng-disabled="expression"指令,在表达式评估值的基础上,它将禁用属性添加到该元素。此外,为了更好的属性值评估,您可以使用ng-attr指令
Markup
标记
<input type="checkbox" ng-attr-name="{{x.filenumber}}" ng-attr-id="{{x.id}}" class ="pdffiles"
value="101SP{{x.initials}}.dwg" ng-disabled="x.status == 'disabled'"/>
If x.statusdoes return a boolvalue then you could directly used ng-disabled="{{x.status}}"
如果x.status确实返回一个bool值,那么您可以直接使用ng-disabled="{{x.status}}"

