2017-04-23 71 views
0

我有以下代码接入子组件参数从父

<div class="data-container" #dataContainer> 
<result (click)="onContainerClick($event, i)" *ngFor="let result of resultItems; let i = index" [result]="result" [index]="i"></result> 

每个结果具有参数 关闭:布尔;

我如何从TS代码中的父级访问?

感谢,

回答

0
. 
. 
. 
import { ViewChildren, QueryList, AfterViewInit } from @angular/core 
. 
. 
. 
export class ParentComponent implements AfterViewInit { 
    @ViewChildren(ResultComponent) resultComps: QueryList<ResultComponent>; 

    ngAfterViewInit() { 
     this.resultComponents.forEach((comp: ResultComponent) => console.log(comp.closed)); 
    } 
} 
+0

它应该是一个数组,它后,我这样做是不确定的。 –

+0

查看我的更新答案 – Dummy