Angular 找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件。不可捉摸
嗨,我无法解决这个问题。我的数据是传递到html的对象数组,我得到以下错误 找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件 Html文件Angular 找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件。不可捉摸,angular,typescript,Angular,Typescript,嗨,我无法解决这个问题。我的数据是传递到html的对象数组,我得到以下错误 找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件 Html文件 <div class="dropdown-menu dropdown-menu-right" *ngIf="userRes" > <div *ngFor="let link of userRes"> <h6 [ngClass]="{'dropdown-header
<div class="dropdown-menu dropdown-menu-right" *ngIf="userRes" >
<div *ngFor="let link of userRes">
<h6 [ngClass]="{'dropdown-header': link.type === 'header', 'dropdown-item': link.type === ''}" i18n *ngIf="link.type != 'separtor'">{{link.title}} </h6>
<div class="dropdown-divider" *ngIf="link.type == 'separator'"></div>
</div>
</div>
组件技术
this.userRes = this.userIntermediateService.userDetail(1)
.subscribe(value => {
console.log(value);
let userRes= Object.keys(value).map(key => value[key])
console.log(this.userRes);
})
任何帮助都将不胜感激。提前感谢。您将变量用作链接,但您的ngFor使用userRes 删除此项。userRes=仅使用以下代码
this.userIntermediateService.userDetail(1)
.subscribe((value) => {
console.log(value);
this.userRes= Object.keys(value).map(key => value[key])
console.log(this.userRes);
});
你可以参考这个答案links或userRes?link是对象数组。userRes是一个变量,因此请尝试使用链接*ngFor=let link of links,您仍在尝试遍历userRes,它不是数组。这是订阅费。您不能迭代订阅。您的links数组是不相关的,因为您正在遍历userRes:*ngFor=let link ofuserRes@NituDhaka现在是你阅读评论的时候了。重新阅读,直到你理解为止。您正在迭代userRes。userRes是订阅,而不是数组。您不断发布名为links的数组,但没有在该数组上进行迭代。您正在迭代userRes。你读过这篇评论吗?如果你在这篇评论中有什么不明白的地方,那是什么?
userRes= [
{
type:'header',
title:'Account'
},
{
title:'Profile',
description:'View your profile',
url:'http://www.test.com/user/profile/url/here',
},
{
title:'Board',
description:'View your board',
url:'http://www.test.com/user/board/url/here',
},
{
type:'separator'
},
{
title:'Settings',
description:'Manage your settings',
url:'http://www.test.com/user/settings/url/here',
}
]
this.userIntermediateService.userDetail(1)
.subscribe((value) => {
console.log(value);
this.userRes= Object.keys(value).map(key => value[key])
console.log(this.userRes);
});