请帮助我,为什么我无法显示确认信息
angular.module('MyApp')
.directive('pwCheck', function () {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel',
link: function (scope, elem, attr, ngModel) {
var val2 = "";
scope.$watch(attr.ngModel, function () {
validate();
})
attr.$observe('pwCheck', function (val) {
validate();
});
var validate = function () {
var val1 = ngModel.$viewValue;
var val2 = attr.pwCheck;
ngModel.$setValidity('passwordVerify', val1 === val2);
HtmlCode
这里我试图验证Emp_Password
对Emp_Cpsw
的{{1}}使用EmpCpsw
指令。指令工作正常但确认消息不弹出
<b>EnterPassword</b> :<input type="password" name="Emp_Password" ng-model="psw1" pw-check="{{psw2}}" required />
<span class="error" ng-show="pwCheck">Password not match</span>
<b>c_password</b><input type="password" name="Emp_Cpsw" ng-model="psw2" pw-check required pw-check="{{psw1}}" />
<span class="error" ng-show="pwCheck">Password not match</span>
答案 0 :(得分:0)
您添加了名为setValidity
的{{1}},因此应在passwordVerify
中使用相同的名称。
view
所以,使用
ngModel.$setValidity('passwordVerify', val1 === val2);