1

我正在使用装饰器@ViewChildren 将数据表单从子组件发送到父组件。

这是我的父组件.ts:

@ViewChildren('child') generalDataComponent : GeneraldataInfoComponent;
 saveAndGoForUpload() {console.log(this.generalDataComponent.generalDataForm.value)}

在我的父 component.html 中:

 <app-generaldata-info  #child></app-generaldata-info>

这是我的孩子 component.ts :

generalDataForm = new FormGroup({
occurenceDate: new FormControl('', Validators.required),
mainCause: new FormControl('', Validators.required),
ageBuilding: new FormControl('', Validators.required)
})

这是我的孩子 component.html :

  <form class="k-form k-form-inline" style="padding-top:4px; " [formGroup]="generalDataForm">

<div class="row">
  <div class="col-md-4 no-padding-left">
    <div style="padding-top: 10px;">
      <span style="font-size: small;">date
      </span>
      <kendo-datepicker [max]="max" formControlName="occurenceDate" [format]="'dd/MM/y'"
        placeholder="DD/MM/YYYY"></kendo-datepicker>
    </div>
  </div>
  <div class="col-md-4" style="padding-top: 10px;">
    <span style="font-size: small ;">age
    </span>
    <div class="row" style="padding-top: 11px; padding-left: 15px;">
      <input type="radio" id="inftwoyears" value="inftwoyears" [formControlName]="'ageBuilding'"
        kendoRadioButton />
      <label class="k-checkbox-label" for="inftwoyears"
        style="padding-left: 10px; padding-right: 10px;">2</label>

      <input type="radio" id="suptwoyears" value="suptwoyears" [formControlName]="'ageBuilding'"
        kendoRadioButton />
      <label class="k-checkbox-label" for="suptwoyears"
        style="padding-left: 10px;">5</label>
    </div>
  </div>
</div>
<br>
<div class="row">
  <div class="col-md-4 no-padding-left">
    <span>cause </span>
  </div>
</div>
<div class="row">
  <div class="col-md-4 no-padding-left">

    <kendo-combobox [data]="mainCauselist" class="form-control" formControlName="mainCause"
    >
    </kendo-combobox>
  </div>
</div>

我收到错误消息cannot read property value of undefined。但是当我写console.log(this.generalDataComponent)它时,它在控制台中给了我:

在此处输入图像描述

4

0 回答 0