【发布时间】:2018-12-14 02:28:40
【问题描述】:
我有一个表单需要将字段设置为有效或无效,因为我想编辑用户,但按钮保持禁用状态
edit.component
ngOnInit() {
this.getForm();
this.getRole();
console.log(this.formGroup.valid)
}
getForm() {
this.formGroup = this.formBuilder.group({
name: ['', Validators.required],
label: ['', Validators.required],
});
}
当我进入页面编辑时,我希望能够将我需要的按钮设置为无效的表单
<button type="submit" mat-button color="primary" [disabled]="!formGroup.valid">Alterar</button>
例如
if(user) {
this.formGroup (invalid)
} else {
this.formGroup (valid)
}
这是我要编辑的页面,但是表单组即使填写了字段也是无效的,为什么?
【问题讨论】:
标签: angular