Here's the code:
TS
user = true;
this.fb.group({
password: ['', [
Validators.required,
this.passwordValidator
]],
newPassword: ['', [Validators.required]],
prevPwd: ['',
Validators.required
]
});
What I'm trying to do here is to remove the prevPwd
or previous password field, when the user is true, but when user is false it should be required the field prevPwd
.
I already tried.
this.formGroup = this.fb.group({
password: ['', [
Validators.required,
this.passwordValidator
]],
newPassword: ['', [Validators.required]],
prevPwd: ['',
Validators.required
]
});
if (user) {
this.formGroup.removeControl('prevPwd');
}
return this.formGroup
But it doesn't work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…