Angularjs按钮禁用无法正常工作

时间:2015-11-03 00:33:45

标签: javascript angularjs html5

我的页面中有以下内容:

<input type="textbox" class="form-control" ng-model="reject_notes" id="rejectnotes" placeholder="Comments">

<button class="btn btn-warning" ng-disabled="!reject_notes" ng-click="rejectorder(reject_notes)">Reject</button>

在我的控制器中我已经初始化了:

$scope.reject_notes = "";

几天前工作了,但不再工作了。当我在文本框中输入一些文本时,i按钮不再启用。我也尝试了以下内容:

<button class="btn btn-warning" ng-disabled="reject_notes.length==0" ng-click="rejectorder(reject_notes)">Reject</button>

知道可能会发生什么吗?

2 个答案:

答案 0 :(得分:0)

你可以使用ng-minlength也可以。禁用按钮直到minlength不正确

<input type="textbox" class="form-control" name ="reject_notes" ng-model="reject_notes" id="rejectnotes" placeholder="Comments" ng-minlength="1">
<button class="btn btn-warning" ng-disabled="ng-disabled='reject_notes.$error.minlength" ng-click="rejectorder(reject_notes)">Reject</button>

答案 1 :(得分:0)

将$ scope.reject_notes初始化为undefined:

$scope.reject_notes = undefined;

然后将ng-disabled条件更改为“!reject_notes”

ng-disabled="!reject_notes"