Loop through an array of strings - angular2

But a very simple thing, but I cannot figure out how to display an array of strings in an 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 doesn't work for me, the text editor shows an error for #numberat ngFor. Is it obsolete in new versions? or am I doing something wrong here?

+4
source share
3 answers

You must declare a variable numberwith let.

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

use let instead of #

<ul>
       <li *ngFor="let number of numberOptions">
          {{number}}
       </li>
</ul>
+3
source
<ul>
       <li *ngFor="let number of numberOptions">
          {{number}}
       </li>
</ul>
+2

Source: https://habr.com/ru/post/1676664/


All Articles