すべての方法を試しましたが、最終的にこのエラーが発生しています。角度2のパスワード照合にエラーが発生しました
Cでのエラー:/laragon/www/myapp/src/app/registration/registration.component.ts(30,9): 'validator:any;型の引数。 } 'は' ValidatorFn 'タイプのパラメータには ssignableではありません。 オブジェクトリテラルは既知のプロパティのみを指定でき、 'validator'は 'ValidatorFn'タイプに存在しません。
は、ここに私のコンポーネントのコードです:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators, Validator, ValidatorFn } from '@angular/forms';
//import { emailValidator, matchingPasswords } from '../../app/validators/validators';
@Component({
selector: 'app-registration',
templateUrl: './registration.component.html',
styleUrls: ['./registration.component.css']
})
export class RegistrationComponent implements OnInit {
private RegistrationForm: FormGroup;
constructor() { }
ngOnInit() {
this.RegistrationForm = new FormGroup({
firstname: new FormControl(null, [
Validators.required,
Validators.minLength(3)
]),
email: new FormControl(null, [
Validators.required,
Validators.pattern(/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-][email protected][a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)
]),
passwords: new FormControl(null, [
Validators.required,
Validators.minLength(6)
]),
confirmpwd: new FormControl(null, [
Validators.required
]),
}, { validator: matchingPasswords.bind('passwords', 'confirmpwd') });
function matchingPasswords(passwordKey: string, confirmPasswordKey: string) {
return (group: FormGroup): { [key: string]: any } => {
let password = group.controls[passwordKey];
let confirmPassword = group.controls[confirmPasswordKey];
if (password.value !== confirmPassword.value) {
return {
mismatchedPasswords: true
};
}
}
}
}
}
http://stackoverflow.com/a/43888447/6294072 – Alex