您好,我遇到了动态步进器的问题,我尝试为每个步骤生成带有表单的步骤。Forms 来自嵌套的 FormGroup 对象。场景继续:
形式:
this.formGroupNested = _formBuilder.group({
formGroup1: _formBuilder.group({
name: new FormControl(),
displayName: new FormControl(),
email: new FormControl(),
adult: new FormControl(),
selectField: new FormControl()
}),
formGroup2: _formBuilder.group({
firstName: new FormControl(),
lastName: new FormControl()
})
});
步进器.html
<mat-horizontal-stepper [linear]="isLinear" #stepperDelivery>
<mat-step *ngFor="let step of steps" [stepControl]="step">
<ng-template matStepLabel>Fill out your name</ng-template>
<!-- <form [formGroup]="step">
</form> -->
</mat-step>
</mat-horizontal-stepper>
我已经工作过 html,但结构不适合步进器。这是工作示例,在 [...] 中是控件
<form
*ngIf="messages; else loading"
[formGroup]="formGroupNested"
[connectForm]="forms">
<div
formGroupName="formGroup1">
<h1>{{ messages.authentication.form.steps.one.title }}</h1>
<uland-text-field
[formGroup]="formGroupNested.controls.formGroup1"
[controlName]="'name'"
[id]="'name'"
[label]="messages.authentication.name.label"
[placeholder]="messages.authentication.name.placeholder"
[isReadOnly]="false"
></uland-text-field>
[...]
</div>
<div
formGroupName="formGroup2">
<h1>{{ messages.authentication.form.steps.two.title }}</h1>
[...]
</div>
</form>
您对如何实现这一目标有任何想法吗?我考虑过ng-template
使用模板别名来生成步骤。问候!
编辑:没有嵌套形式,我的步进器看起来像这样,我想它更容易维护:
<mat-horizontal-stepper [linear]="isLinear" #stepperDelivery>
<mat-step [stepControl]="formGroup">
<ng-template matStepLabel>Fill out your name</ng-template>
<cms-development-form
[messages]="messages"
[formGroup]="formGroupSingle">
</cms-development-form>
</mat-step>
</mat-horizontal-stepper>