Loop through array of strings - angular2

Amit Chigadani picture Amit Chigadani · May 8, 2017 · Viewed 20.9k times · Source

Yet very basic thing, but I am unable to figure out how to display array of strings in html template in angular2.

.html

<ul>
       <li *ngFor="#number of numberOptions">
          {{number}}
       </li>
</ul>

.ts

this.numberOptions= ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"];

The above trick is not working for me, text editor shows error for #number in ngFor. Is this deprecated in new versions? or am I doing anything wrong here?

Answer

SrAxi picture SrAxi · May 8, 2017

You have to declare the variable number with let.

   <li *ngFor="let number of numberOptions">
      {{number}}
   </li>