как связать выходные значения другого компонента с элементом управления формой в моем компоненте

Это мой 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 вместо использования методов. можно ли избежать методов обновления


person Ramakanth Reddy    schedule 25.09.2019    source источник


Ответы (1)


почему вы не используете formControl?

это может связать ваш Html с элементами управления формы <input [formControl]="category"></input>

person Khashayar Pakkhesal    schedule 25.09.2019