如何更改FormBuilder生成的数据的格式

时间:2019-06-10 13:20:48

标签: angular

    import win32com.client
    from datetime import datetime as dt
    from datetime import timedelta,timezone
    import pytz
    import linecache
    from xlrd import open_workbook
    from xlutils.copy import copy
    import xlwt

    outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

给出一个看起来像这样的myForm.value。

ngOnInit() {
    this.pgForm = this.fb.group({
      pgroup: ['', Validators.required],
      needs: this.fb.array([this.fb.control('')]),
    });

  }

  get needs() {
    return this.pgForm.get('needs') as FormArray;
  }
  addNeed() {
    this.needs.push(this.fb.control(''));
  }

我想要一个看起来像这样的myForm.value;以便与我的API很好地配合

Values: { "pgroup": "blah", "needs": [ "blah", "blah", "blah" ]}

是否可以在formBuilder上实现?

2 个答案:

答案 0 :(得分:1)

您将不得不拥有一个FormControlFormGroup name:的{​​{1}}数组:

FormControl

与添加时相同:

ngOnInit() {
  this.pgForm = this.fb.group({
    pgroup: ['', Validators.required],
    needs: this.fb.array([this.fb.group({ need: this.fb.control('') })])
  });
}

答案 1 :(得分:0)

是的,您必须将一个表单组推送到数组。

ngOnInit() {
    this.pgForm = this.fb.group({
      pgroup: ['', Validators.required],
      needs: this.fb.array([this.fb.group({ need: [''])]),
    });

  }

  get needs() {
    return this.pgForm.get('needs') as FormArray;
  }
  addNeed() {
    this.needs.push(this.fb.group({ need: [''] }));
  }