Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Angular ng-attr for the disabled attribute

Tags:

angularjs

I am trying to use ng-attr to conditionally add an attribute to an element. My code is something like this:

<label for="theID" 
       ng-attr-disabled="{{true || undefined}}"
       class="control-label">
  Some Label
</label>

What I get by inspecting the element is this:

<label translate="" for="theID" 
       ng-attr-disabled="{{true || undefined}}" 
       class="control-label ng-scope" disabled="disabled">
  Some Label
</label>

But expectation is:

<label translate="" for="theID" 
       ng-attr-disabled="{{true || undefined}}" 
       class="control-label ng-scope"
       disabled>
  Some Label
</label>

am I wrong altogether about how it works?

Thanks

like image 924
Mark Avatar asked Nov 29 '25 06:11

Mark


1 Answers

I don't think you should care about it, in your case. When value is falsy, disabled is not present. When value is truthy, is present - and it's all about presence in HTML about attributes like this (like required on inputs, validation care about presence required="false" makes input required). For example, you can style it dependent on attribute presence: MDN Attribute selectors.

like image 175
Radek Anuszewski Avatar answered Dec 01 '25 00:12

Radek Anuszewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!