简体   繁体   English

如何禁用AngularJS输入中的复选框?

[英]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.

相关问题 如何使用angularjs为我的条件设置复选框? - How can i make checkbox for my condtion using angularjs? 如何从jquery中的输入复选框行将我的代码更改为可点击的行? - How can I change my code into clickable row from input checkbox row in jquery? 如果我选中复选框,如何启用复选框中的输入? 因为当我选中输入类型的复选框时,它总是禁用 - How to enable the input in checkbox if i check the checkbox? cuz it always disable when i check the checkbox with input type 如何在ExtJS中禁用网格上的复选框? - How can I disable checkbox on the grid in ExtJS? 如何验证angularjs中的复选框? - How can I validate checkbox in angularjs? 如何使用 AngularJS 基于下拉选择值禁用输入文本框? - How can i disable an input text box based on dropdown selection value using AngularJS? 在PHP中单击复选框时,如何禁用输入? - How do I disable an input when checkbox is clicked in PHP? 如何使用angularjs在不更改输入类型复选框的ng-if条件的情况下禁用按钮? - How to disable button without changing of ng-if condition for input type checkbox using angularjs? 如何将 localStorage 应用于输入复选框? - How can I apply localStorage to input checkbox? 如何从加载开始就禁用我在amcharts中的标题? - How can i disable my title in amcharts from beginning on loading?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM