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/