0

这是我的 html 代码,它基本上是一个表单。

<form [formGroup]="calculatedForm" fxLayout="column" fxLayoutGap="15px" fxLayoutAlign="start space-betwen">
    <label for="category">CATEGORY</label>
      <app-toggle-button-group
        [items]="categories"
        [selectedItem]="getselectedCategory()"
        (valueChange)="updateCategory($event)"
        [disableButtons]="calculatedForm.value.system">
      </app-toggle-button-group>

      <label for="input_interval">INTERVAL</label>
      <app-toggle-button-group
        [items]="inputIntervals"
        [selectedItem]="getselectedInterval()"
        (valueChange)="updateInterval($event)"
        [disableButtons]="calculatedForm.value.system">
      </app-toggle-button-group>

      <label for="aggregation">AGGREGATION</label>
      <app-toggle-button-group
        [items]="aggregations"
        [selectedItem]="getselectedAggregation()"
        (valueChange)="updateAggregation($event)"
        [disableButtons]="calculatedForm.value.system">
      </app-toggle-button-group>

      <app-kpi-unit 
        [selectedUnitID]="selectedUnitId()" 
        (changedUnitID)= "selectUnit($event)"
        [disableSelect]="calculatedForm.value.system">
      </app-kpi-unit>

    </form>

这是我在控制器中的表单属性

  calculatedForm = this.formBuilder.group({
    id: new FormControl(''),
    identifier: new FormControl(''),
    category: new FormControl('', [Validators.required]),
    aggregation: new FormControl(null, [Validators.required]),
    input_interval: new FormControl('', [Validators.required]),
    operator: new FormControl('', [Validators.required]),
    unit_id: new FormControl(null),
    org_unit: new FormControl('', [Validators.required]),
    system: new FormControl(false),
    deleted: new FormControl(false),
    assignedKpiId: new FormControl(null)
  });

正如您在 html 代码中看到的那样,我正在使用组件发出的事件中的方法来更新我的表单控件

updateCategory(category: buttonGroupType) {
    this.calculatedForm.controls['category'].patchValue(category.name);
  }

但我的要求是使用 formcontrolName 而不是使用方法进行绑定。是否可以避免更新方法

4

1 回答 1

0

你为什么不使用formControl

这可以将您的 Html 绑定到表单控件 <input [formControl]="category"></input>

于 2019-09-25T14:17:35.070 回答