24

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?

3 Answers 3

48

Use this

<input type="submit" class="btn btn-info pull-right btn-lg btn-block" ng-disabled="associate.JobStatus == 2" />
Sign up to request clarification or add additional context in comments.

Comments

28

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

Comments

0

You have to use like this.

<input type="submit" class="btn btn-info pull-right 
btn-lg btn-block" ng-disabled="associate.JobStatus === '2'" />

1 Comment

Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.

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.