Angularjs form Password Authentication custom instruction implementation code _ANGULARJS

Source: Internet
Author: User

HTML code

<form name= "Form" >
    <input type= "password" name= "password" "ng-model=" password "required placeholder=" Please enter password >
    <input type= "password" name= "passwordconfirm" ng-model= "passwordconfirm" equal-to= "password" placeholder= "Please enter password again" >
    <span ng-show= "form.passwordconfirm. $error. Equalto" > two times Password inconsistency </span>
  </form>

Js

Angular.module ("Valid", []). Directive ("Equalto", function () {return {require: "Ngmodel", Link:function (SC Ope, Ele, Attrs, ctrl) {Console.log (scope);//print current scope console.log (attrs);//Print current Label Properties list Console.log (ctrl) ;//print the current CTRL var target = attrs["Equalto"];//gets the custom directive property key value if (target) {//Determines whether the key exists scope. $watch (Target,
        function () {//There is a start listening to its value CTRL. $validate ()//change manually Invoke validation})//Get the current model controller's parent controller Formcontroller  var Targetctrl = ctrl.$ $parentForm [target];//Gets the specified model controller console.log (Targetctrl) ctrl. $validators. Equalto = function (Modelvalue, Viewvale) {//Custom validator content var targetvalue = Targetctrl. $viewValue;//Get the loss of the password Enter value return Targetvalue = = viewvale;//is equal to passwordconfirm value} CTRL. $formatters. Push (function (VA
        Lue) {Console.log ("the value in which data is being formatted:", value) return value; Ctrl. $parsers. Push (function (value) {conSole.log ("value in which data is being converted:", value) return value; })
      }
    }
  }
})

Demo Address: https://tianyouh.github.io/angularPasswordConfirm/

Related Article

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.