我的反应性表单无法在其基础表单组中找到表单控件。
这是错误:
ERROR Error: Cannot find control with path: 'mailSettings -> sendReminder'
在ngOnInit()
中,我通过初始化表单
private _initForm(): void {
const mail: FormGroup = this._fb.group({
sendReminder: [false, [Validators.required]],
contacts: [this._fb.array([]), [Validators.required]]
});
const exposure: FormArray = this._fb.array([]);
this.settingsForm = this._fb.group({
photoUrl: [this.settings.photoUrl, []],
isActive: [this.settings.isActive, [Validators.required]],
idMdm: [this.settings.idMdm, [Validators.required]],
idPms: [this.settings.idPms, [Validators.required]],
name: [this.settings.name, [Validators.required]],
functionalCurrency: [this.settings.functionalCurrency, [Validators.required]],
mailSettings: [mail, []],
exposures: [exposure, []]
});
}
然后在组件HTML中通过以下方式引用
:
<form [formGroup]="settingsForm">
<mat-vertical-stepper>
<!-- company data -->
<mat-step>
<ng-template matStepLabel>Company Data</ng-template>
<mat-slide-toggle color="primary" #enabled formControlName="isActive"></mat-slide-toggle> {{enabled.checked ? 'Enabled' : 'Disabled'}}<br><br>
<mat-form-field class="name"><input matInput placeholder="Name" formControlName="name"></mat-form-field><br>
<mat-form-field class="marginRight16px"><input matInput placeholder="Id PMS" formControlName="idPms"></mat-form-field>
<mat-form-field class="marginRight16px"><input matInput placeholder="Id MDM" formControlName="idMdm"></mat-form-field>
<mat-form-field class="marginRight16px"><input matInput placeholder="Functional Ccy" formControlName="functionalCurrency"></mat-form-field><br>
</mat-step>
<!-- contact info -->
<mat-step>
<ng-template matStepLabel>Contact Info</ng-template>
<div formGroupName="mailSettings">
<mat-slide-toggle color="primary" #reminder formControlName="sendReminder"></mat-slide-toggle> {{reminder.checked ? 'Send' : 'Do not send'}}<br><br>
</div>
</mat-step>
<!-- exposure data -->
<mat-step>
<ng-template matStepLabel>Exposure</ng-template>
</mat-step>
</mat-vertical-stepper>
</form>
对我所缺少的东西有什么想法吗?任何帮助表示赞赏!
欢呼