Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs ng-disabled doesn't add disabled to button

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?

like image 244
Ray Suelzer Avatar asked Oct 25 '13 20:10

Ray Suelzer


People also ask

How do I give conditions in NG-disabled?

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 .

Which of the following is true about Ng-disabled directive?

Q 9 - Which of the following is true about ng-disabled directive? A - ng-disabled directive can enable a given control.

Is disabled in AngularJS?

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).


2 Answers

Use this

<input type="submit" class="btn btn-info pull-right btn-lg btn-block" ng-disabled="associate.JobStatus == 2" />
like image 123
gartox Avatar answered Oct 12 '22 15:10

gartox


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}}">
like image 22
vineet Avatar answered Oct 12 '22 15:10

vineet