1

I want to use a loop count in angular2. To execute a command ten times. *ngFor work like foreach

<div *ngFor="item in items"> Repeatative Item content </div>

but i want same thing like this

  <div *ngFor="i=0;i<10;i++"> Repeatative Item content </div>

edit: I've found the answer . It works for me.

Community
  • 1
  • 1

1 Answers1

2

You can do this I think:

<div *ngFor="item in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"> Repeatative Item content </div>
Jelle den Burger
  • 1,428
  • 17
  • 31
  • thanks, but i want use something like for i=0;i++;i – mohamad javad Taherian Sep 05 '16 at 06:51
  • Angular2 doesn't currently provide anything like that without arrays. You should be aware that the size of arrays defined in the view is limited. I don't know the limit (25 or something in that scale). You'll get an error if it exceeds that size. In this case you need to move the array to the components class. – Günter Zöchbauer Sep 05 '16 at 06:54