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? ;) 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. 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.

Sign up to request clarification or add additional context in comments.

2 Comments

I think I missed very basic thing. Thanks for answering.
@SaiUnique , I am glad that you found your solutions , :)
1

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

export class ExampleComponent{

   @Input('exData1') exData1: any;
   @Input('exData2') exData2: any;
}

1 Comment

Thanks for answering.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.