How to pass multiple data to child component using @Input

I have a question, what if we want to pass multiple data to a child component using @Input

how to do it.

If we have something like this:

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

      

How to get data in child component. Using two @Input

s?

  • If so, how do we know which data is included @Input

    ? Questions for ordering?

  • If not, how can this be achieved?

Sorry if I missed the base point on this.

Thank..

+3


source to share


2 answers


You can achieve this in the child component by this

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

      




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

      

Here exampleData1

and exampleData2

are the data from your parent component and exData1

and exData2

are the input names that you can get in your child component by the above code.

+6


source


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



export class ExampleComponent{

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

      

+1


source







All Articles