child 组件从 parent 组件接收数据时出错

Error while child component receiving data from parent component

我将数据 parent 传递给了 child

`<tag-editor[item]="item"></tag-editor>`

这里的项目有数据

Child分量:

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)
  }
}