密码和确认密码一致的Angularjs验证

来源:互联网 发布:淘宝自动刷销量软件 编辑:程序博客网 时间:2024/06/05 19:43
<input type='password' id='pw1' name='pw1'  ng-model='pw1' ng-required/><input type='password' id='pw2' name='pw2'  ng-model='pw2' ng-required pw-check='pw1'/>
指令定义部分:
angular.module('myApp.directives', [])  .directive('pwCheck', [function () {    return {      require: 'ngModel',      link: function (scope, elem, attrs, ctrl) {        var firstPassword = '#' + attrs.pwCheck;        elem.add(firstPassword).on('keyup', function () {          scope.$apply(function () {            var v = elem.val()===$(firstPassword).val();            ctrl.$setValidity('pwmatch', v);          });        });      }    }  }]);
错误提示
<div class='msg-block' ng-show='myForm.$error'>  <span class='msg-error' ng-show='myForm.pw2.$error.pwmatch'>    Passwords don't match.  </span></div>
0 0
原创粉丝点击