Loop through array of strings - angular2

心已入冬 提交于 2019-12-10 14:11:40

问题


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?


回答1:


You have to declare the variable number with let.

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



回答2:


use let instead of #

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



回答3:


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


来源:https://stackoverflow.com/questions/43851357/loop-through-array-of-strings-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!