Angularjs按钮禁用无法正常工作

Angularjs button disable not working properly

本文关键字:常工作 工作 按钮 Angularjs      更新时间:2023-09-26

我的页面中有以下内容:

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

知道可能会发生什么吗?

您也可以使用ng 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>

将$scope.reject_notes初始化为未定义:

$scope.reject_notes = undefined;

然后将ng禁用条件更改为"!reject_notes"

ng-disabled="!reject_notes"