遍历字符串数组-angular2 [英] Loop through array of strings - angular2
本文介绍了遍历字符串数组-angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
还很基本,但是我无法弄清楚如何在angular2的html模板中显示字符串数组.
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"];
上述技巧对我不起作用,文本编辑器显示ngFor
中#number
的错误.新版本是否已弃用?还是我在这里做错了什么?
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?
推荐答案
您必须使用let
声明变量number
.
<li *ngFor="let number of numberOptions">
{{number}}
</li>
这篇关于遍历字符串数组-angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文