8

I have a question that if we want to pass multiple data to child component using @Input how to achieve that.

If we have component something like this:

<ex-comp [exData1]="exampleData1" [exData2]="exampleData2"></ex-comp>

How to get the data in the child component. Using two @Inputs?

  1. If so, how does we know which data comes into which @Input? Order matters?

  2. If not, how to achieve that?

Sorry if I miss basic point in this.

Thanks..

2
  • 1
    I'd say you could have tried this in your code before asking? ;)
    – AVJT82
    Commented Jul 31, 2017 at 6:51
  • @AJT_82, I should've tried it before asking. But, I wanted to know all the theoritical things before doing it practically.
    – Sai
    Commented Jul 31, 2017 at 7:43

2 Answers 2

20

You can achieve that in your child component by this

 @Input()exData1;
 @Input()exData2;

<ex-comp [exData1]="exampleData1" [exData2]="exampleData2"></ex-comp>

Here exampleData1 and exampleData2 are data from your parent component and exData1 and exData2 are the input names that you can access into your child component by above given code.

2
  • I think I missed very basic thing. Thanks for answering.
    – Sai
    Commented Jul 31, 2017 at 12:10
  • @SaiUnique , I am glad that you found your solutions , :) Commented Jul 31, 2017 at 12:11
1

You just create public variables with @Input() attribute:

export class ExampleComponent{

   @Input('exData1') exData1: any;
   @Input('exData2') exData2: any;
}
1
  • 1
    Thanks for answering.
    – Sai
    Commented Jul 31, 2017 at 12:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.