-1
嗨任何一個可以幫助我如何可以驗證密碼和確認密碼字段中AngularJS如何檢查密碼和確認密碼在AngularJS同
嗨任何一個可以幫助我如何可以驗證密碼和確認密碼字段中AngularJS如何檢查密碼和確認密碼在AngularJS同
有可以實現這一目標這麼多的方法。一個方法是使用指令
<input type="password" name="confirmPassword"
ng-model="registration.user.confirmPassword"
required
compare-to="registration.user.password" />
<div ng-messages="registrationForm.confirmPassword.$error"
ng-messages-include="messages.html"></div>
//指令
var compareTo = function() {
return {
require: "ngModel",
scope: {
otherModelValue: "=compareTo"
},
link: function(scope, element, attributes, ngModel) {
ngModel.$validators.compareTo = function(modelValue) {
return modelValue == scope.otherModelValue;
};
scope.$watch("otherModelValue", function() {
ngModel.$validate();
});
}
};
};
module.directive("compareTo", compareTo);
請通過#1對導閱讀[如何提問](http://stackoverflow.com/help/how爲了將來的問題)。 – muenchdo
請在這裏發佈任何問題之前做一些初步研究。無論如何下面的答案會幫助你。 – Iceburg