我将数据舞会父母传递给了孩子
`<tag-editor[item]="item"></tag-editor>`
项目有数据
儿童组件:
export class TagEditorComponent implements OnInit, OnChanges {
@Input() private item: Tag;
ngOnInit() {
console.log(this.item)
}
ngOnChanges() {
console.log(this.item)
}
,但我只有2个undefined
。
我该如何修复?
//Try this :
import {OnInit, SimpleChanges, OnChanges} from '@angular/core';
export class TagEditorComponent implements OnInit, OnChanges {
@Input() private item: Tag;
ngOnInit() {
console.log(this.item)
}
ngOnChanges(changes : SimpleChanges) {
if(typeof changes['item'] !== 'undefined'){
console.log(this.item)
}
}