#Need an array as long as a number in an ngFOr
10 messages · Page 1 of 1 (latest)
write a custom pipe that transforms a number to an iterable, then use pipe inside ngFor
a simple solution would be:
<p *ngFor="let j of [].constructor(i.length)">
<app-carta></app-carta>
</p>
but what is i? a string? a number? an array?
or use generator function inside component
protected *iterate(num: number) {
for (let i = 0; i < num; i++) {
yield i
}
}
i is a number
this worked tysm
could you explain how this works rq btw?
[].constructor(10) is the same as new Array(10) so it creates an array of 10 items but all empty.
then your *ngFor will iterate over the 10 empty elements
keep in mind, that it creates a new array every time change detection is run