someone might run into some kind of situation when using ngFor without collections. But it seems that everyone likes to set the array variable and bind *ngFor as the following code:
an array
// typescript public bignumber:number[]=[1,2,3,4,5,6,7,8,9,10] //html <ng-template *ngFor="let item of bignumber | index as i"> p {{i}} </ng-template>
This is not suitable for a template, if you want to run 5 or 10 times, and you need to set a new variable, then you can iterate. So I want to use array new array in the template, but this is not work. No matter new Array() or any that you would use with the array keyword, it will parse our variable, but not the define keyword.
error log
ERROR TypeError: _co.Array is not a function
Now I am using a complicated way to solve this situation:
template
<ng-template [ngForOf]="[].map.call({length:10},[].map).fill('')" let-i="index"> p {{i}} </ng-template>
Is it possible to use clean code, for example:
[ngForOf]="Array(10).fill()"
angular angular2-template
Rach Chen Dec 01 '17 at 4:10 2017-12-01 04:10
source share