使用 API - Angular 响应式表单中的数据加载编辑表单复选框

Load edit form Checkboxes with data from API - Angular Reactive Form

当表单处于编辑模式时,我试图用 API 中的值填充复选框。
当我硬编码复选框的值时它正在工作 stackblitz working, but when I load the data from the service through http request, I got the following error in console. also i attached the new stackblitz 有错误

我想通了,忘记用*ngIf了。我更正了 stackblitz

在组件 html 模板文件中,只需将表单包裹在 **<div *ngIf="rentPeriodList">**

<div *ngIf="rentPeriodList">
  <form [formGroup]="myForm" (ngSubmit)="submit()">
    <label
      formArrayName="rentPeriods"
      *ngFor="let rentPeriod of rentPeriodsArr.controls; index as i"
    >
      <input type="checkbox" [formControlName]="i" />
      {{ rentPeriodList[i].name }}
    </label>

    <button>submit</button>
  </form>
</div>