[英]How to access Array Object without key name in HTML with Angular
这将取决于您希望如何在视图中显示它。
你有一个数组数组。 因此,要在 HTML 中显示Estanteria 2
,类似这样的操作就可以了;
<div *ngFor="let item of array">
<!-- this will show Estanteria 2 -->
<div>{{ item[3] }}</div>
</div>
如果你想遍历第二个数组中的所有值,你可以:
<div *ngFor="let item of array">
<!-- this will show all the values in the second array -->
<div *ngFor="let value of item">{{ value }}</div>
</div>
将数据加载到变量itemList
<div *ngFor="let item of itemList; let i = index;" >
<div *ngFor=" let x of item" >{{ x}}</div>
</div>
尝试如下,组件
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
items = [[1,2,3], [4,5,6]];
}
HTML
<table>
<tr *ngFor="let item of items">
<td *ngFor="let element of item | keyvalue">{{element.value}}</td>
</tr>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.