0

I just want to create a simple loop in html

such as

for(int i = 1; i < n ; i++){
  //do something
}

i found may soltion but non of them working for me here is one of them

<li *ngFor='#loop of counter(5) ;#i= index'>{{i}}</li>

can anyone help me with this

Masti tyem
  • 51
  • 9
  • 1
    `#` is old angular 2 beta syntax, check the tutorials: https://angular.io/guide/template-syntax#ngfor – AT82 Oct 29 '17 at 07:21
  • 1
    ... and since this is a basic question, I suggest you start off with the TOH tutorial, you'll learn the basics :) https://angular.io/tutorial – AT82 Oct 29 '17 at 07:25
  • one more thing, calling methods in template is a bad idea, I suggest you rethink that https://stackoverflow.com/questions/37876533/ngfor-running-an-infinite-loop-in-angular2 – AT82 Oct 29 '17 at 08:24

1 Answers1

0

Hope this helps you :)

Component

counter(number){
    // do something with the number passed
    let list: Array<number> = [1, 2, 3];
    return list;
  }

Template

<li *ngFor='let loop of counter(5);let i= index'>{{i}}</li>

And Better start with some tutorials this might help

Rahul Singh
  • 19,030
  • 11
  • 64
  • 86