Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngform复选框选择数组提交_Angular_Typescript_Angular Forms - Fatal编程技术网

Angular ngform复选框选择数组提交

Angular ngform复选框选择数组提交,angular,typescript,angular-forms,Angular,Typescript,Angular Forms,我使用了一个使用ngform的步骤向导。用户单击“下一步”后,将在本地保存用户选择,直到表单在最后一步提交 我在表单的第1步中引入了复选框。我可以建立一个新选中复选框的数组,我还可以为表单的其余部分获得一个数组。我曾尝试将两者结合起来,但我的表单模型不喜欢它 以下是我迄今为止所做的一系列努力- 主要问题-您会在上面的stackblitz中注意到,在步骤1完成并且选中复选框后,选择数组仍然为空 html-复选框 <div *ngFor="let selection of intelSelec

我使用了一个使用ngform的步骤向导。用户单击“下一步”后,将在本地保存用户选择,直到表单在最后一步提交

我在表单的第1步中引入了复选框。我可以建立一个新选中复选框的数组,我还可以为表单的其余部分获得一个数组。我曾尝试将两者结合起来,但我的表单模型不喜欢它

以下是我迄今为止所做的一系列努力-

主要问题-您会在上面的stackblitz中注意到,在步骤1完成并且选中复选框后,选择数组仍然为空

html-复选框

<div *ngFor="let selection of intelSelections; let i=index">
  <label class="form-check-label">
    {{selection}}
  </label>
  <input class="form-check-input" [ngModel]="isSelected(selection)" (ngModelChange)="onChange(selection, $event)" type="checkbox" name="intelgroup_{{i}}">
</div>
保存步骤1

save(form: any): boolean {
    this.formDataService.setPersonal(this.personal);
    return true;
}
this.personal
是表单上提交的另一个输入数据数组

我可以看到两种选择:

  • 组合
    this。选择电话
    this.personal
  • [ngModel]=“isSelected(selection)”
    了解如何将personal.selection添加到ngModel

  • 将保存方法更新为:

    save(form: any): boolean {
        this.personal.selection = this.selectedIntel;
        this.formDataService.setPersonal(this.personal);
        return true;
    }
    

    我不明白问题是什么……你为什么不直接做
    this.personal.selection=this.selectedIntel在您的保存方法中?您可以添加此作为答案吗?谢谢,这就是我所需要的!
    
    save(form: any): boolean {
        this.personal.selection = this.selectedIntel;
        this.formDataService.setPersonal(this.personal);
        return true;
    }