I have an input button that I want to set to disabled if a user selects a certain value from a select box:
Select menu:
<select id="jobstatus" name="jobstatus" ng-model="associate.JobStatus" class="form-control">
<option value="0">Current</option>
<option value="1">Former</option>
<option value="2">Never worked there</option>
</select>
Input Button:
<input type="submit" class="btn btn-info pull-right
btn-lg btn-block" ng-disabled="{{associate.JobStatus === '2'}}" />
Now when I am viewing the source, when I do select option 2
, the input button element changes from value ng-disabled="false"
to ng-disabled="true"
but the disabled attribute is not applied to the button.
What am I doing wrong here?
The ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .
Q 9 - Which of the following is true about ng-disabled directive? A - ng-disabled directive can enable a given control.
The ng-disabled Directive in AngularJS is used to enable or disable the HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usually applied on the form field (i.e, input, select, button, etc).
Use this
<input type="submit" class="btn btn-info pull-right btn-lg btn-block" ng-disabled="associate.JobStatus == 2" />
Angular Doc ngDisabled
Curly braces means the notation {{ }} to bind expressions to elements is built-in Angular markup.
Use:
<input type="submit" ng-disabled="associate.JobStatus == 2" />
Instead of:
<input type="submit" ng-disabled="{{associate.JobStatus == 2}}" />
same as for ng-show / ng-hide / ng-if, you can use the model expression itself instead of {{}}
For Example:-
Use:
<div ng-show="someObject.showProperty">
Instead of:
<div ng-show="{{someObject.showProperty}}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With