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.
Its not removeControls
function, its removeControl
function.
this.formGroup.removeControl("prevPwd");
This will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.