2017-04-23 45 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