Currently, I am working on user registration in Angular. Here is my part of code where I'm trying to compare Password and ConfirmPassword:
comparePasswords(fb: FormGroup) {
let confirmPswrdCtrl = fb.get('ConfirmPassword');
if (confirmPswrdCtrl.errors == null || 'passwordMismatch' in confirmPswrdCtrl.errors) {
if (fb.get('Password').value != confirmPswrdCtrl.value)
confirmPswrdCtrl.setErrors({ passwordMismatch: true });
else
confirmPswrdCtrl.setErrors(null);
}
}
The problem is that Angular warns me about confirmPswrdCtrl, that it can be possibly null:
error TS2531: Object is possibly 'null'.
What's wrong and how can I solve this? Thanks in advance.