0
我有一个多维数组与两个键,它看起来像这样。Angular 4 |尽管多维阵列循环
user: any = {};
// index is from a for loop to add to the user (this part works perfectly)
this.user[index++] = {
Name: name,
Age: age,
}
但是我的问题是,我想使用* ngFor通过循环在我的角度HTML模板,但是我收到一个错误说它不支持它。所以我的问题是,我如何循环访问这个用户数组并打印出数组中每个键的名称和年龄值?
我尝试:
<li *ngFor="let user of users">{{user.Name}} - {{user.Age}}</li>
的错误我收到:
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
谢谢。
'user:any = {};'不是数组!尝试'user:any = [];' –
^他不是试图访问对象键值,只是声明是错误的。 'user:any [] = []'应该修正它? – Skeptor
@MohamedAbbas唉,你说得对。我一生中有一个小时试图解决这个问题。非常感谢! – Nicster15