How to disable my checkbox from login in AngularJS?

<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 add something to this snippet that disables the input flag based on another entry in AngularJS, for example {{x.status}}. I just tried:

 <input type="checkbox" name="{{x.filenumber}}" id="{{x.id}}" class = "pdffiles" value="101SP{{x.initials}}.dwg" {{x.status}} /> 

Where status:'disabled' , but this gave the result

 {{x.status}}="" 

inside the input element ... which I don’t understand at all why. But that seemed the easiest way.

+6
source share
1 answer

You need to use the directive ng-disabled="expression" , according to the main value of the evaluation of the expression, it adds the disabled attribute to this element. You can also use the ng-attr directive to better evaluate attribute values.

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 wrote a bool value, you could use ng-disabled="{{x.status}}" directly

+10
source

Source: https://habr.com/ru/post/984462/


All Articles