禁用提交按钮时,表格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-禁用:的这里有一个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屋!
查看全文