有没有办法在 angular 反应形式中使用 angular 指令(*ngfor)?

Is there way to use angular directives(*ngfor) in angular reactive forms?

提交表单时,有没有一种方法可以保留所有数据而不用替换 Angular 响应式表单中随 Angular 指令更改的相同数据(标记)? 我尝试了下面的代码,但是我找不到获取所有“标记”输入的方法。

    <div *ngFor="let item of stuData">
      <label>{{item.name}}</label>
      <input type="number" min="0" max="100" placeholder="Marks" formControlName="marks">
    </div>

你或许可以像这样用动态形式组织一些东西:

https://www.bitovi.com/blog/managing-nested-and-dynamic-forms-in-angular

<ng-container *ngFor="let userFormGroup of usersForm.controls.users.controls; let i = index">
  <div [formGroup]="userFormGroup">
    {{stuData[i]}}
     <label>
      Mark
      <input type="text" formControlName="marks">
    </label>
  </div>
</ng-container>

并且在 .ts

let fgArray: FormGroup[];

fgArray.forEach(element => {
  this.fb.group({
    mark: ['', null],
  });
})

this.usersForm = this.fb.group({
      users: this.fb.array(fgArray)
})