Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through array of strings - angular2

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?

like image 748
Amit Chigadani Avatar asked May 08 '17 15:05

Amit Chigadani


1 Answers

You have to declare the variable number with let.

   <li *ngFor="let number of numberOptions">
      {{number}}
   </li>
like image 183
SrAxi Avatar answered Oct 12 '22 00:10

SrAxi