Ng-Form-4

 

In this example of ng-form the save is enable only when the form is valid as both of the fields required. When user enter valid email and password then the save button is enable otherwise disable. formName.$valid is true when form is valid.

 
 
 
<!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 ng-submit="save(user)" name="myForm" novalidate> Email: <input type="email" name="uname" required ng-model="user.userName"> <span style="color:red" ng-show="myForm.uname.$error.required && myForm.uname.$dirty">User Name is required</span> <br /> Password: <input type="password" name="password" required ng-model="user.password"> <span style="color:red" ng-show="myForm.password.$error.required && myForm.password.$dirty">Password is required</span> <br /> <button ng-disabled="!myForm.$valid" type="submit">save</button> </ng-form> </div> </body> </html>
Output