当表单与 AngularJS 无效时禁用提交按钮 [英] Disable submit button when form invalid with AngularJS
本文介绍了当表单与 AngularJS 无效时禁用提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格是这样的:
<form name="myForm">
<input name="myText" type="text" ng-model="mytext" required />
<button disabled="{{ myForm.$invalid }}">Save</button>
</form>
如您所见,如果输入为空,按钮将被禁用,但当它包含文本时不会变回启用.我怎样才能让它工作?
As you may see, the button is disabled if the input is empty but it doesn't change back to enabled when it contains text. How can I make it work?
推荐答案
您需要使用表单名称,以及 ng-disabled:这是 Plunker 的演示
You need to use the name of your form, as well as ng-disabled: Here's a demo on Plunker
<form name="myForm">
<input name="myText" type="text" ng-model="mytext" required />
<button ng-disabled="myForm.$invalid">Save</button>
</form>
这篇关于当表单与 AngularJS 无效时禁用提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文