When I try to pass data from parent to child component. I\'m getting undefined message in the console. Data is in the form of array.
parent.component.html
It can be done using Input()
decorator. See below code -
parent.component.ts -
import { Component } from '@angular/core';
@Component({
selector: 'app-parent',
template: `
`,
styleUrls: ['./parent.component.css']
})
export class ParentComponent{
parentMessage = "message from parent"
constructor() { }
}
child.component.ts -
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-child',
template: `
Say {{ childMessage}}
`,
styleUrls: ['./child.component.css']
})
export class ChildComponent {
@Input() childMessage: string;
constructor() { }
}
More Information