2013-10-25 33 views
21

我有,我想,如果用戶從選擇框中選擇一個特定的值設置爲禁用輸入按鈕:angularjs NG-禁用禁用不添加到按鈕

選擇菜單:

<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 type="submit" class="btn btn-info pull-right 
btn-lg btn-block" ng-disabled="{{associate.JobStatus === '2'}}" /> 

現在,當我查看源代碼,當我做選擇的選項2,從價值ng-disabled="false"輸入按鈕元素更改爲ng-disabled="true"但禁用的屬性不應用於按鈕。

我在這裏做錯了什麼?

回答

23

角文件ngDisabled

大括號表示符號{{}}來表達結合元件是內置的角標記。

用途:

<input type="submit" ng-disabled="associate.JobStatus == 2" /> 

相反的:

<input type="submit" ng-disabled="{{associate.JobStatus == 2}}" /> 

相同NG-顯示/ NG隱藏/ NG-如果,您可以使用模型 表達式本身而不是{{}}

例如: -

用途:

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

相反的:

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