AngularJS Form Directives

The AngularJS ng-form directive is used to keep nested form. Browsers do not allow nesting of elements.

Syntax

AngulaJS ng-form has following properties

PropertyDescription
$validIt is used to check inputs are valid or not.
$invalidIt is used to check inputs are invalid or not.
$pristineIt is used to check inputs are unmodified by the user or not.
$dirtyIt is used to check inputs are modified by the user or not. Its just revers of pristine.
$errorThis contains collection of invalid control's input, if a validation fail it return true, otherwise false.

Example

<!doctype html>
<html ng-app>  
<head>  
<title>My first AngularJS ng-form Directive code</title>  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js">  
</script> 
 <script>
   function formData($scope) {
   $scope.userName = 'Jimi Scotts';
   $scope.email = 'jimi.s@aol.com';
   $scope.password = '1234';
   }
  </script>
<style>
.error {
  border: 1px solid #FF552A;
  color:#FF552A;
}
</style>
</head>  
<body>  
<form name="login" ng-controller="formData" novalidate>  
  <div ng-form="loginform">
    <p>
    User Name : 
    <input type="text" name="userName" ng-model="userName" placeholder="User Name" required/>  
    <div ng-show="loginform.userName.$dirty && loginform.userName.$invalid">  
      <span class="error" ng-show="loginform.userName.$error.required">
	  User name is required.
	  </span>  
    </div>  
    </p>
  <p>Email : 
    <input type="email" name="email" ng-model="email" placeholder="Email ID" required/>  
    <div ng-show="loginform.email.$dirty && loginform.email.$invalid">  
      <span class="error" ng-show="loginform.email.$error.required">
	  Email is required.
	  </span>
      <span class="error" ng-show="loginform.email.$error.email">  
      Enter a valid email.
	  </span>  
    </div>
  </p>

  <p>Password : 
    <input type="password" name="pass" ng-model="password" placeholder="Password" required/>  
    <div ng-show="loginform.pass.$dirty && loginform.pass.$invalid">  
      <span class="error" ng-show="loginform.pass.$error.required">
	  Password is required.
	  </span>  
    </div>
  </p>
  </div>  
  <button type="submit" ng-disabled="(login.loginform.userName.$dirty 
  && login.loginform.userName.$invalid)  
  || (login.loginform.email.$dirty && login.loginform.email.$invalid) 
  || login.loginform.pass.$dirty 
  && login.loginform.pass.$invalid">Submit Form</button>  
</form>   
  
</body>  
</html> 
Try Now

See Also

AngularJS Built-in Filters
AngularJS Built-in Directives
AngularJS Expression
AngularJS Built-in Events
AngularJS Scope Methods
AngularJS Built-in Services
AngularJS Controller Inheritance
AngularJS Custom Directives


 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.