How do I check form validity with angularjs?

前端 未结 4 1900
渐次进展
渐次进展 2020-12-13 11:52

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.

4条回答
  •  佛祖请我去吃肉
    2020-12-13 12:18

    When you put

    tag inside you ngApp, AngularJS automatically adds form controller (actually there is a directive, called form that add nessesary behaviour). The value of the name attribute will be bound in your scope; so something like ...
    will satisfy:

    A form is an instance of FormController. The form instance can optionally be published into the scope using the name attribute.

    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.

提交回复
热议问题