[英]How can I disable my checkbox from AngularJS input?
<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}}. 我需要能够在此片段中添加一些内容,根据另一个AngularJS输入(例如{{x.status}})禁用输入复选框。 I tried simply doing: 我试过简单地做:
<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. 但它似乎是最简单的路线。
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-attr
directive 您需要使用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.status
does return a bool
value then you could directly used ng-disabled="{{x.status}}"
如果x.status
确实返回bool
值,那么你可以直接使用ng-disabled="{{x.status}}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.