0

我将数据舞会父母传递给孩子

`<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

我该如何解决?

4

1 回答 1

2
//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)
  }
}
于 2017-03-11T15:28:04.920 回答