如何解决使用@ViewChildren Angular 时得到“未定义”
我正在使用装饰器@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('',ageBuilding: new FormControl('',Validators.required)
})
这是我的子组件.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)
时,它会在控制台中显示:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。