我在 FormArray 方面遇到问题,可能需要一些帮助。\n我有一个带有变量 FormArray 的表单,它可以工作,我可以将数据发送到后端。\n问题是,我无法设置从我收到的数据中的值后端。
\n这是打字稿代码:
\nthis.form = this.fb.group({\n title: new FormControl("",[Validators.required]),\n actors: new FormArray([])\n})\n\nthis.moviesService.getMovie(this.movieId).subscribe(movieData => {\n this.movie = movieData;\n this.form.patchValue({\n title: this.movie.title,\n actors: this.movie.actors, \n })\n})\nRun Code Online (Sandbox Code Playgroud)\n然后在 html 中单击按钮,我调用此函数:
\naddActor(){\n const actorsForm = this.fb.group({\n actor: \'\',\n role: \'\'\n })\n this.actors.push(actorsForm);\n}\n\nremoveActor(i: number){\n this.actors.removeAt(i);\n}\nRun Code Online (Sandbox Code Playgroud)\n和 HTML:
\n<form [formGroup]="form" (submit)="onSubmit()">\n <table formArrayName="actors">\n <tr>\n <th colspan="2">Besetzung:</th>\n <th width="150px">\n <button type="button" mat-stroked-button color="primary" (click)="addActor()">Hinzuf\xc3\xbcgen +</button>\n </th>\n </tr>\n <tr *ngFor="let actor of form.get(\'actors\')[\'controls\']; let i=index" [formGroupName]="i">\n <td>\n …Run Code Online (Sandbox Code Playgroud)