` Item here has data Child component: export class TagEditorComponent implem" /> ` Item here has data Child component: export class TagEditorComponent implem" /> ` Item here has data Child component: export class TagEditorComponent implem"/>

Error while child component receiving data from parent component

250 views Asked by At

I passed data prom parent to child

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

Item here has data

Child component:

export class TagEditorComponent implements  OnInit, OnChanges {
@Input() private item: Tag;
ngOnInit() {
  console.log(this.item)
}
ngOnChanges() {
  console.log(this.item)
}

But i got only 2 undefined.

How can i fix it?

1

There are 1 answers

0
Amit Chigadani On BEST ANSWER
//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)
  }
}