如何在角JS中使用- in父组件访问子组件窗体数组值.
示例代码
parent
<div [formGroup]="createForm">
<div formArrayName="pFormArray">
<div *ngFor="let pFormArray of pFormArrayArray.controls; let j=index" [formGroupName]="j">
{{ j }}
<app-child [pForm]="pForm"></app-child>
<!-- </div> -->
</p-accordionTab>
</p-accordion>
</div>
</div>
</div>
child
<div class="ui-fluid" [formGroup]="pForm">
<div class="ui-g ui-g-nopad" *ngFor="let sForm of sFormArray.controls;
index as i; first as isFirst"
[formGroupName]="i">
<input type="text" formControlName="name">
</div>
</div>发布于 2018-10-30 10:25:16
您可以使用ViewChild获取对子组件的引用。
尝试以下代码
parent.component.html
<child #childRef></child>parent.component.ts
@ViewChild('childRef') child : ChildComponent;
ngAfterViewInit(){
console.log(this.child.getValue());
}child.component.ts
getValue(){
return 'value';
}查看演示
https://stackoverflow.com/questions/53060800
复制相似问题