Angular 角形6材料步进垫阶梯嵌套反应形式

Angular 角形6材料步进垫阶梯嵌套反应形式,angular,angular-material,angular-reactive-forms,angular-material-stepper,Angular,Angular Material,Angular Reactive Forms,Angular Material Stepper,您好,我有一个动态步进器的问题,我试图为每个步骤生成带有表单的步骤。表单来自嵌套的FormGroup对象。 情况如下: 表格: stepper.html <mat-horizontal-stepper [linear]="isLinear" #stepperDelivery> <mat-step *ngFor="let step of steps" [stepControl]="step"> <ng-template matStepLab

您好,我有一个动态步进器的问题,我试图为每个步骤生成带有表单的步骤。表单来自嵌套的FormGroup对象。 情况如下:

表格:

stepper.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>

使用FormArray创建动态表单。另外,请在给定的GitHub示例中找到实现的示例:

TS:
表格:表格;;
恩戈尼尼特(){
this.formGroup=this.formBuilder.group({
表单:this.formBuilder.array([this.init2()])
});
}
附加项(){
this.form=this.formGroup.get('form')作为FormArray;
this.form.push(this.init2());
}
init2(){
返回此.formBuilder.group({
blogHeading:new FormControl(“”,[validator.required]),
});
}
HTML:
步骤{{i+1}
用户名是必需的
新页

在每个步骤中显示正确的表单组是否有问题?只是想知道我应该在每个步骤中使用简单的被动表单,还是可以使用完整的嵌套被动表单。对于大型嵌套表单,html存在问题,因为只有一个标记,它不适合stepper结构,因为stepper结构预测每个步骤的新表单。
  <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>
<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>
  <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>
TS:
  form: FormArray;

ngOnInit() {
    this.formGroup = this.formBuilder.group({
      form : this.formBuilder.array([this.init2()])
    });
  }
  addItem() {
    this.form = this.formGroup.get('form') as FormArray;
    this.form.push(this.init2());
  }
  init2() {
    return this.formBuilder.group({
      blogHeading: new FormControl('', [Validators.required]),
        });
  }
HTML:
   <form [formGroup]="formGroup">
      <mat-horizontal-stepper  formArrayName="form">
      <mat-step [formGroupName]="i" *ngFor="let customerGroup of formGroup.controls.form.controls; let i = index">
        <ng-template matStepLabel>Step {{i + 1}}</ng-template>
        <mat-form-field>
            <input matInput placeholder="blogHeading" formControlName="blogHeading" required>
            <mat-error *ngIf="!(f2.blogHeading.valid && f2.blogHeading.touched)">
              Username is Required
            </mat-error>
          </mat-form-field>
                <div>
          <button mat-button  (click)="addItem()">New Page</button>
      </div>
      </mat-step>
    </mat-horizontal-stepper>
  </form>