1
votes

I have a form like this

<form name="myForm">
    <input name="myEmail" type="email"/>

    {{myForm.$invalid}}
</form>

I need to bind my input field with ng-model to validate correctly the form. Why AngularJs is unable to validate this form just like this?

Even, the property myForm.myEmail.$invalid only exist if I bind the input with ng-model. Why is this so?

If validation only exist with ngModel directive, why angularjs give me the value myForm.$invalid to false? a better response would not be undefined?

2

2 Answers

2
votes

Why AngularJs is unable to validate this form just like this?

Because validation makes sense only in context of ngModel directive, as this is what actually allows validation capabilities by registering corresponding model controller (ngModelController) with parent form directive controller, which orchestrates validation functionality.

Check the source to see how input directives are implemented and what they do with ngModel controller: https://github.com/angular/angular.js/blob/71cf28cf06295e0936f706c048bc07e6c963acc4/src/ng/directive/input.js#L1708

0
votes

Because angular validates the model, not the html. If you don't bind to a model, then, as far as angular is concerned, there's nothing to validate.