如何检查的形式有效性与angularjs? [英] How do I check form validity with angularjs?
问题描述
我很新的angularjs。说我的应用程序有一个形式。使用检查,我注意到,如果angularjs认为,形式是无效的,它增加了一个NG-无效类的形式。可爱。
I'm very new to angularjs. Say my app has a form. Using the inspector, I noticed that if angularjs thinks that the form is invalid, it adds an ng-invalid class to the form. Lovely.
如此看来,以检查的形式是有效的,我需要我的污染code。与jQuery选择?什么是angularjs方式来表示形式有效性不使用表单控制器?
So it seems that in order to check if the form is valid I need to pollute my code with Jquery selector?! What is the angularjs way to indicate form validity without using a form controller?
推荐答案
当你把<形式>你内心
标记ngApp,AngularJS会自动将表单控制器(居然还有是一条指令,名为格式
的补充所必要的行为)。
When you put <form>
tag inside you ngApp, AngularJS automatically adds form controller (actually there is a directive, called form
that add nessesary behaviour).
所以检查表单的有效性,您可以检查 $ scope.yourformname的价值。美元范围内有效
属性。
So to check form validity, you can check value of $scope.yourformname.$valid
property of scope.
更多信息,您可以在开发指南部分有关表单得到的。
More information you can get at Developer's Guide section about forms.
这篇关于如何检查的形式有效性与angularjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!