私は4つのフォームフィールドを持っています。私は 'oldpass'フィールドと 'newpass'フィールドが反応するフォームを使って同じであるかどうかをチェックしたいと思います。角度2の反応形式のカスタム検証
this.changePasswordForm = fb.group({
'oldpass': ['', Validators.compose([Validators.required, Validators.minLength(6)])],
'newpass': ['', Validators.compose([Validators.required, Validators.minLength(6)])],
'confirmpass': ['', Validators.compose([Validators.required])],
'otp': ['']
},{validator: CustomValidator.matchConfirmFields('newpass', 'confirmpass')});
「newpass」と「confirmpass」フィールドの検証には、次のコードを使用できます。
static matchConfirmFields(pass: string, confirmpass: string) {
return (group: FormGroup): {[key: string]: any} => {
let spass = group.controls[pass];
let sconfirmpass = group.controls[confirmpass];
if (spass.value !== sconfirmpass.value) {
return {
mismatchedPasswords: true
};
}
}
}
どのようにi 'はoldpass' と 'NEWPASS' フィールドと同様の方法を検証します。
https://scotch.io/tutorials/how-to-implement-a-custom-validator-directive-confirm-password-in-angular-2最初 – misha130
おかげでどのようにmisha..butこれをチェック'oldpass'と 'newpass'の2番目のバリデータを呼び出しますか?私はあなたの質問を誤解した場合、私に教えてくださいと私に教えてくださいこれを削除します – vishnu