angularjs ng-disabled不会向按钮添加禁用

时间:2020-11-29 19:41:50

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.

现在,当我查看源时,当我选择选项2时,输入按钮元素从值ng-disabled =“false”变为ng-disabled =“true”,但禁用的属性不应用于按钮。

What am I doing wrong here?

我在这做错了什么?

2 个解决方案

#1


42  

Use this

用这个

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

#2


24  

Angular Doc ngDisabled

Angular Doc ngDisabled

Curly braces means the notation {{ }} to bind expressions to elements is built-in Angular markup.

大括号意味着将表达式绑定到元素的符号{{}}是内置的Angular标记。

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

与ng-show / ng-hide / ng-if相同,您可以使用模型表达式本身而不是{{}}

For Example:-

例如:-

Use:

使用:

<div ng-show="someObject.showProperty">

Instead of:

代替:

<div ng-show="{{someObject.showProperty}}">

#1


42  

Use this

用这个

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

#2


24  

Angular Doc ngDisabled

Angular Doc ngDisabled

Curly braces means the notation {{ }} to bind expressions to elements is built-in Angular markup.

大括号意味着将表达式绑定到元素的符号{{}}是内置的Angular标记。

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

与ng-show / ng-hide / ng-if相同,您可以使用模型表达式本身而不是{{}}

For Example:-

例如:-

Use:

使用:

<div ng-show="someObject.showProperty">

Instead of:

代替:

<div ng-show="{{someObject.showProperty}}">