简体   繁体   English

AngularJS按钮禁用无法正常工作

[英]Angularjs button disable not working properly

I have the following in my page: 我的页面中有以下内容:

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

and in my controller i have initialized: 在我的控制器中,我已经初始化:

$scope.reject_notes = "";

This worked a few days back but is not working anymore. 几天前,此方法有效,但不再起作用。 When i enter some text in my textbox, i button is not enabling anymore. 当我在文本框中输入一些文本时,i按钮不再启用。 I also tried the following: 我还尝试了以下方法:

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

Any idea what might be happening? 知道会发生什么吗?

You can do it by using ng-minlength also..it disabled button until minlength not proper 您也可以使用ng-minlength..it禁用按钮,直到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>

Initialize your $scope.reject_notes as undefined: 将$ scope.reject_notes初始化为未定义:

$scope.reject_notes = undefined;

then change your ng-disabled condition to "!reject_notes" 然后将您禁用ng的条件更改为“!reject_notes”

ng-disabled="!reject_notes"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM