简体   繁体   English

找不到类型为“object”的不同支持对象“[object Object]”。 - 上下文菜单问题

[英]Cannot find a differ supporting object '[object Object]' of type 'object'. - context menu issues

I have issues with context menu.我有上下文菜单的问题。 I am not sure why, I made similar thing many times but now I am unable to pass it.我不知道为什么,我做了很多次类似的事情,但现在我无法通过。 When I deleted this line:当我删除这一行时:

<div *ngFor="let element of contextMenu">
</div>

Context menu works fine (but I need this line to fill my context menu. This is part of html:上下文菜单工作正常(但我需要这一行来填充我的上下文菜单。这是 html 的一部分:

<mat-menu #contextMenu="matMenu">
    <ng-template matMenuContent>
    <div *ngFor="let element of contextMenu">
    </div>
    </ng-template>
</mat-menu>

And my context menu object:我的上下文菜单对象:

  @Input() contextMenu: MenuElement[];

And html with filled input:和填充输入的html:

  <lib-mp-file-explorer
          [fileElements]="fileElements | async"
          [path]="currentPath"
          [canNavigateUp]="canNavigateUp"
          [topMenu]="topMenu"
          [contextMenu]="contextMenu"
          (folderAdded)="addFolder($event)"
          (elementRemoved)="removeElement($event)"
          (navigatedDown)="navigateToFolder($event)"
          (navigatedUp)="navigateUp()"
          (elementRenamed)="renameElement($event)"
          (elementMoved)="moveElement($event)"
        >
  </lib-mp-file-explorer>

And my construction:而我的建设:

this.contextMenu = [
      {
        name: 'Open in Mark',
        icon: 'M',
        action: undefined,
        disabled: true
      }, 
      ...
]

I hate this error now:我现在讨厌这个错误:

core.js:5828 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. core.js:5828 错误错误:找不到类型为“object”的不同支持对象“[object Object]”。 NgFor only supports binding to Iterables such as Arrays. NgFor 仅支持绑定到可迭代对象,例如数组。

But my array is iterable TT但我的数组是可迭代的 TT

Your menu reference variable has the same name..您的菜单参考变量具有相同的名称..

<mat-menu #contextMenu="matMenu">

..as the array you are trying to loop through ..作为您尝试循环的数组

<div *ngFor="let element of contextMenu">

A template reference variable is not iterable.模板引用变量不可迭代。

Try renaming your array:尝试重命名您的数组:

<div *ngFor="let element of menuElements">

And Input() :Input()

@Input() menuElements: MenuElement[];

and then进而

this.menuElements = [
 // your data
]

You can check what there are actual values in your contextMenu :您可以检查contextMenu有哪些实际值:

<p>contextMenu {{ contextMenu | json }}

However, your error says that it is object, so you can use keyvalue pipe since Angular 6:但是,您的错误表明它是对象,因此您可以从 Angular 6 开始使用keyvalue管道:

<div *ngFor="let item of contextMenu | keyvalue">
    Key: <b>{{item.key}}</b> and Value: <b>{{item.value}}</b>
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到&#39;对象&#39;类型的不同支持对象&#39;[object Object]&#39; - Cannot find a differ supporting object '[object Object]' of type 'object' 找不到其他支持对象&#39;[对象对象] - Cannot find a differ supporting object '[object Object] Angular:*ngFor 循环给我错误:找不到类型为“object”的不同支持对象“[object Object]” - Angular: *ngFor loop giving me error: Cannot find a differ supporting object '[object Object]' of type 'object' 过滤多面阵列,但管道返回错误 - 找不到&#39;对象&#39;类型的不同支持对象&#39;[object Object]&#39; - Filtering a multifaceted array, but the pipe return an error - Cannot find a differ supporting object '[object Object]' of type 'object' 角度4无法找到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组 - Angular 4 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 9 找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular 9 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 12:找不到支持 object 类型为“object”的“[object Object]” - Angular 12: Cannot find a differ supporting object '[object Object]' of type 'object' 找不到类型为“数字”的不同支持对象“33.265625” - Cannot find a differ supporting object '33.265625' of type 'number' Angular 问题:找不到支持“object”类型的 object“[object Object]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular problem: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误:找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到Iterables(如数组)如何解决 - error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays how to solve
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM