Home > Enterprise >  How to receive an array as @Input from index.html custom element tag?
How to receive an array as @Input from index.html custom element tag?

Time:10-27

I have created a custom element in angular. The element tag is shown as below:

     <test-reco userId="I8763" [productId]="['101','B102']"> </test-reco>

I am calling it in index.html. Now, It has two inputs one is userId that is of type string and another is an array of productId. I am recieveing these as input inside my component as shown below:

    export class test implements OnInit {
       @Input() userid = '';
       @Input() productid: any[];
    }

Inside my component the productId is coming as undefined. Can anyone please tell me what I am doing wrong? I also tried passing it like this:

productId="['101','B102']"

But in this case it came as string and not as an array.

CodePudding user response:

You can expload it with (",") Substr 1 and -1 for removing the [ and ]

CodePudding user response:

Your name should be the same as given below.

<test-reco [userId]="I8763" [productId]="['101','B102']"> </test-reco>
export class test implements OnInit {
       @Input() userId= '';
       @Input() productId: any[];
    }
  • Related