从父级访问子组件参数

时间:2017-04-23 09:27:25

标签: typescript angular2-forms

我有以下代码

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

每个结果都有一个参数   关闭:布尔值;

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

谢谢,

1 个答案:

答案 0 :(得分: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));
    }
}