Ng-Form-3

 
In this example we can check the validation of form that uesrname or password field is required etc.
 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <ng-form name="myForm" novalidate> User Name:<input type="text" name="uname" required ng-model="user.userName"><br /> Password:<input type="password" name="password" required ng-model="user.password"><br /> <button ng-disabled="!myForm.$valid" type="submit">save</button> </ng-form> <pre>myForm.$valid:<b>{{myForm.$valid}}</b></pre> <pre>myForm.uname.$dirty:<b>{{myForm.uname.$dirty}}</b></pre> <pre>myForm.uname.$pristine:<b>{{myForm.uname.$pristine}}</b></pre> <pre>myForm.password.$error.required:<b>{{myForm.password.$error.required}}</b></pre> <pre>myForm.uname.$error.required:<b>{{myForm.uname.$error.required}}</b></pre> </div> </body> </html>
Output