我在我的应用程序中创建了一个下拉组件,但是我收到了以下错误:无法读取属性' toUpperCase'未定义的("
ncaught Error: Template parse errors:
TypeError: Cannot read property 'toUpperCase' of undefined ("
</a>
<ul class="dropdown-menu">
<li [ERROR ->]*ngFor="let item of {{lista}}" >
<a href="#paper">{{item.id}}</a>
</li>
"): ng:///AppModule/PfDropdownComponent.html@12:8
Can't bind to '*ngFor' since it isn't a known property of 'li'. ("
</a>
<ul class="dropdown-menu">
<li [ERROR ->]*ngFor="let item of {{lista}}" >
<a href="#paper">{{item.id}}</a>
</li>
组件:
@Input() lista = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
]
HTML:
<ul class="dropdown-menu">
<li *ngFor="let item of {{lista}}" >
<a href="#paper">{{item.id}}</a>
</li>
</ul>
答案 0 :(得分:0)
尝试这样:
使用<li *ngFor="let item of lista">
代替<li *ngFor="let item of {{lista}}">
<ul class="dropdown-menu">
<li *ngFor="let item of lista">
<a href="#paper">{{item.id}}</a>
</li>
</ul>