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>}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With