[英]Error while child component receiving data from parent component
我将数据舞会父母传递给孩子
`<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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.