[英]How to remove the field 'prevPwd' from the formbuilder in angular
Here's the code:这是代码:
TS 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
.我在这里尝试做的是删除
prevPwd
或以前的密码字段,当用户为真时,但当用户为假时,应该需要字段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.但它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.