ANGULARJS Study Notes 5_form1

Source: Internet
Author: User

1. Getting Started

<form ng-controller= "Validationcontroller" Name= "Form1" novalidate>
<p> <input type= "Submit" ng-disabled= "Form1. $invalid" >
<input type= "email" name= "myemail" ng-model= "e-mail" ng-minlength= "ten" ng-maxlength= "required>"

Using the ng-show directive, color:red is displayed when the message is $dirty or $invalid .
<span style= "color:red" ng-show= "Form1. myemail. $Dirty && form1.myemail.$Invalid">

<span ng-show= "Form1. myemail. $error. Required ">email is required.</span><span ng-show= "Form1. myemail. $error. Email ">invalid Email address.</span><span ng-show= "Form1. myemail. $error. minlength ">min length 10.</span><span ng-show= "Form1. myemail. $error. MaxLength ">max length 50.</span>

</span>
</p>
</form>

The form properties novalidate are used to disable browser default validation. $dirty form is filled with records$valid The contents of the field are valid$invalid field contents are illegal $pristine The form does not fill in the record 2. Using angular-messages
<! DOCTYPE html>


    <title>form</title>
      <script type= ' text/javascript ' src= ' http://cdn.bootcss.com/angular.js/1.4.9/angular.js ' > </script>
     <script type= ' text/javascript ' src= ' http://cdn.bootcss.com/ Angular.js/1.4.9/ angular-messages.js ' ></script>    
    <style type= "Text/css";
    . Form1 {
        Transition:all linear 0.5s;
       background:transparent;
    }
    </style>

<body ng-app= "A8_8";
    < Form Name= "Form1" ng-controller= "Form1controller" class= "Form1" NOVALIDATE>
<label ng-show= "User.ID! = undefined" ng-model= "user.id" >
User id:<span>{{user.id}}</span>
</label><br>
<label>enter text: <input type= "Email" ng-model= "email1" name= "Myemail" required ng-minlength= "ten" maxlength= "/>" </label>
<div style= "Color:red"ng-messages= "Form1.myemail. $error"Ng-messages-multiplerole= "Alert"ng-if= "Form1.myemail. $touched">
<divNg-message= "Required" >email is required.</div>
<div ng-message= "Email" >invalid Email address.</div>
<div ng-message= "minlength" >min length 10.</div>
<div ng-message= "maxlength" >max length 50.</div>
</div>
<p> <input type= "Submit" value= "commit" ng-disabled= "form1.$invalid"/></p>
<span class= "error" ng-show= "Form1.myemail. $error. Required" >Required!</span><br>
<code>form1.myemail. $valid = {Form1.myemail. $valid}}</code><br>
<code>form1.myemail. $error = {Form1.myemail. $error}}</code><br>
<code>form1. $valid = {Form1. $valid}}</code><br>
<code>form1. $error. Required = {{!!! Form1. $error .required}}</code><br>
<buttonNg-click= "Reset ()" ng-disabled= "isunchanged (user)" >RESET</button>
<button ng-click= "Update(user) "Ng-disabled=" Form1. $invalid | | isunchanged (user) ">SAVE</button> <br>
</body>
3. Data SubmissionNo traditional submit, it is model-based background processing
<script type= "Text/javascript" >
var app = Angular.module (' A8_8 ', [' ngmessages ']);
App.controller (' Form1controller ', [' $scope ', function ($scope) {
$scope. user = {email: ' [email protected] '};
$scope. master = {email: ' [email protected] '};
$scope. Update = function (user) {
$scope. master = angular.copy (user);
Console.log (' save ' +user);
user.id=1;
Console.log (user);
};
$scope. reset = function () {
$scope. User = Angular.copy ($scope. master);
};
$scope. isunchanged = function (user) {
return angular.equals (user, $scope. master);
};
}]);
</script>

ANGULARJS Study Notes 5_form1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.