Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Input value treated as object instead of array

Tags:

angular

In my parent component, I populate the array as follows:

myarray = [];
...
... // forloop
this.myarray.push({id: <someid>, name: <somename>});

In my parent template, I set this as input to the child

<childcomponent [myarray]="myarray"></childcomponent>

In my child component, I declare the input as:

@Input() myarray;

But when I tried to iterate and get the length, I cannot iterate and length is 0. And then I tried to do "typeof" it returns an object. I tried to write to console with console.log(myarray) and it gives me:

[]
0: {id: <someid>, name: <somename>}
like image 532
iPhoneJavaDev Avatar asked May 08 '26 19:05

iPhoneJavaDev


1 Answers

The Array in JavaScript is a global object which contains a list of items.

Please take a look at my demo.

You can specify type as Array to make object iterable.

like image 168
Chintan Joshi Avatar answered May 10 '26 16:05

Chintan Joshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!