1 に答える
0
多分それはあなたを助けます。フォーム内の 2 つの値が等しいことを検証するために、このディレクティブを作成しました。ディレクティブは同等性をチェックし、手動で検証結果をフォームに設定します。
ディレクティブの例:
angular
.module('app')
.directive('sameAs', sameAs);
function sameAs() {
var directive = {
link: link,
restrict: 'A',
require: 'ngModel',
scope: {
sameAs: '='
}
};
return directive;
////////////
function link(scope, element, attrs, ctrl) {
ctrl.$validators.match = function (modelValue, viewValue) {
return viewValue === scope.sameAs;
};
}
}
使用例:
<form name="testForm">
<input name="newPassword" type="password"
ng-model="formData.newPassword">
<input name="confirmPassword" type="password"
ng-model="formData.confirmPassword"
same-as="formData.newPassword">
<span ng-show="testForm.confirmPassword.$error.match">Passwords is not the same!</span>
</form>
于 2015-10-05T13:44:06.953 に答える