I am trying write a validator to match password in angular 6, below is the code of component class
export class comnentClass implements OnInit {
addAccountForm = new FormGroup({
"username": new FormControl('',
[ Validators.required],this.shouldContainUniqueUsername.bind(this)),
"password": new FormControl('', Validators.required),
"confirmPassword": new FormControl('',[Validators.required,this.checkPasswords.bind(this)]),
});
get username() {
return this.addAccountForm.get('username');
}
get password() {
return this.addAccountForm.get('password');
}
get confirmPassword() {
return this.addAccountForm.get('confirmPassword');
}
onSubmit() {
}
checkPasswords(control: AbstractControl) {
let pass = this.password;
console.log("password is "+pass)
return pass === control.value ? null : { notSame: true }
}
}
Every time when angular load component class, I am getting below exception
core.js:1598 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'get' of undefined
TypeError: Cannot read property 'get' of undefined
at SysAdminComponent.get [as password] (sys-admin.component.ts:53)
How can I get the values of other input type while writing validator to match password?