【发布时间】:2017-12-24 15:38:29
【问题描述】:
当我尝试将数据从父组件传递到子组件时。我在控制台中收到未定义的消息。数据是数组的形式。
parent.component.html
<div class="section welcome-section fp-section fp-table" *ngFor="let section of sections">
<div class="fp-tableCell">
<app-question-card [data]="section"></app-question-card>
</div>
</div>
child.component.ts
@Input() data;
question = [];
constructor() {
this.question = this.data;
}
ngOnInit() {
console.log(this.question); //returns undefined
}
【问题讨论】:
-
将作业移至
ngOnInit。@Input在ngOnChanges之前不可用 -
输入属性不应该已经在 ngOnInit 中水合了吗?
-
constructor => ngOnChanges => ngOnInit => ngAfterContentInit ... -
@Jota.Toledo
ngOnChanges在ngOnInit之前被解雇
标签: angular typescript