Reputation: 432
I have two components parent & child, and i want to pass the category defined in parent to be used in child. But getting error undefined.
Parent Component:
export class MenuComponent implements OnInit {
category: string;
constructor() { }
ngOnInit() {
this.category = "Human";
}
And the Child component is:
export class MenuListComponent implements OnInit{
@Input() category: string;
// category = 'Man';
constructor() { }
ngOnInit() {
console.log(this.category);
}
Parent component template
<div class="container">
<div class="row">
<app-menu-list></app-menu-list>
</div>
</div>
Output is undefined.
Upvotes: 0
Views: 3124
Reputation: 73377
You actually need to pass your variable to the child:
<app-menu-list [category]="category"></app-menu-list>
Upvotes: 4