9
<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:

<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

{{x.status}}=""

within the input element...which I don't understand why at all. But it seemed like the simplest route.

1
  • 1
    You can't add attributes dynamically using Interpolation method to your html tag. In your case you can simply do ng-disabled="x.status" Commented Mar 30, 2015 at 21:20

1 Answer 1

17

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

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}}"

Sign up to request clarification or add additional context in comments.

6 Comments

do you mean {{x.status}} == 'disabled' ? Also, what would status equal? What if I don't what the checkbox disabled?
Using @Rahil Wazir's comment above, I did ng-disabled="{{x.status}}" where status:'true' or status:'false"
@Christine268 hey don't use interpolation with ng-disabled directive, ng-disabled directive is matured enough to evaluate scope variables, It must be ng-disabled="x.status" if x.status has boolean
@pankajparker when I change it to ng-disabled="x.status" it no longer works. status either equals true or false. ng-disabled="{{x.status}}" is what's working for me.
@Christine268 I updated answer, Now you can do upvote & accept it Thanks :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.