0

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.

2
  • 1
    Can you add template code as well please so we can see how you're passing the input? Commented Jan 27, 2018 at 12:15
  • @user184994 Added the template Commented Jan 27, 2018 at 12:27

1 Answer 1

4

You actually need to pass your variable to the child:

<app-menu-list [category]="category"></app-menu-list>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.