Using Angularjs's directive, we can easily implement the inspection function. The code is as follows:
1 //Password Verification Directive2Ftitappmodule.directive (' PwCheck ', [function () {3 return {4Require: ' Ngmodel ',5Linkfunction(Scope, Elem, Attrs, ctrl) {6 varFirstpassword = ' # ' +Attrs.pwcheck;7Elem.add (Firstpassword). On (' KeyUp ',function () {8Scope. $apply (function () {9 varv = elem.val () = = =$ (Firstpassword). Val ();TenCtrl. $setValidity (' Pwmatch ', v); One }); A }); - } - } the}]);
Demo HTML code (feedback section please refer to http://www.cnblogs.com/ilovewindy/p/3795993.html):
1 <Divclass= "Form-group">2 <label for= "UserPassword">Password</label>3 <inputtype= "Password"class= "Form-control"ID= "UserPassword"name= "UserPassword"4 placeholder= "Please enter password"Ng-model= "Selecteduser.userpassword">5 </Div>6 <Divclass= "Form-group has-feedback"7 Ng-class= "{' has-success ':!usrmgrform.confirmpassword. $pristine && usrmgrform.confirmpassword. $valid,8 ' Has-error ':!usrmgrform.confirmpassword. $pristine && usrmgrform.confirmpassword. $invalid} " >9 <label for= "ConfirmPassword">Confirm Password</label>Ten <inputtype= "Password"class= "Form-control"ID= "ConfirmPassword"name= "ConfirmPassword" One placeholder= "Please enter your password again"Ng-model= "Selecteduser.confirmpassword"Pw-check= "UserPassword"> A <DivNg-show= "!usrmgrform.confirmpassword. $pristine && tagname.confirmpassword $valid"> - <spanclass= "Glyphicon glyphicon-ok form-control-feedback"></span> - </Div> the <DivNg-show= "!usrmgrform.confirmpassword. $pristine && usrmgrform.confirmpassword $invalid"> - <spanclass= "Glyphicon glyphicon-remove form-control-feedback"></span> - </Div> - </Div>
The effect is as follows: