简体   繁体   English

Angular 12:找不到支持 object 类型为“object”的“[object Object]”

[英]Angular 12: Cannot find a differ supporting object '[object Object]' of type 'object'

Hopefully someone out there can assist me in this issue.希望有人可以帮助我解决这个问题。

I have a component in Angular that I am trying have send a list of objects to a modal component to display in a table but I keep getting the error listed in the title.我在 Angular 中有一个组件,我正在尝试将对象列表发送到模态组件以显示在表格中,但我不断收到标题中列出的错误。 Console logging the data it shows that it is receiving it in an Array but it still won't go.控制台记录数据,它显示它正在数组中接收它,但它仍然不会 go。

First this is how I am getting the data from the service:首先,这是我从服务中获取数据的方式:

Plan Service计划服务

    return this.http.get<BasePartFormatted[]>(
      `$apiurl`
    );
  }

Then in the ngOnInit this is how I am setting the parts list for the table bind:然后在 ngOnInit 中,这就是我为表绑定设置零件列表的方式:

Part List Component TS零件清单组件 TS

partList$: Observable<BasePartFormatted[]>;
selectedParts: BasePartFormatted[] | null; <-- for primeng selection bind
ngOnInit: void {
    this.partList$ = this.planService.getParts(this.flowID);
}

To render the list in the table I use the async pipe. Also I use primeng for the framework and pipe the selected items in the list for the component modal.为了呈现表中的列表,我使用异步 pipe。此外,我将 primeng 用于框架,pipe 将列表中的选定项目用于组件模态。 The selected items get dropped into an array based on the primeng documentation.根据 primeng 文档,所选项目被放入一个数组中。

Part List HTML零件清单 HTML

<p-table
    #partsList
    [value]="partList$ | async"
    [(selection)]="selectedParts"
  >

  <ng-template #modal_content_go let-modal>
    <modal-form
      [selectedParts]="selectedParts" 
    ></modal-form>
  </ng-template>

In the modal component I try to bring it in as an @Input:在模态组件中,我尝试将其作为@Input 引入:

Modal Component TS模态分量 TS

@Input() selectedParts: BasePartFormatted[];

And try to render in the modal html:并尝试在模态 html 中渲染:

Modal HTML模态 HTML

  <p-table
    #selectedParts
    [value]="selectedParts"
  >
...
 <ng-template pTemplate="body" let-part>
      <td>{{ part.item1}}</td>
      <td>{{ part.item2}}</td>
      <td>{{ part.item3}}</td>
      <td>{{ part.item4}}</td>
    </ng-template>

To check what the selectedParts actually were, I created a button on the Modal html to console.log the output and it says that it is an array for two objects: Console.log showing an array of two objects为了检查 selectedParts 实际上是什么,我在 Modal html 上创建了一个按钮到 console.log output 并且它说它是两个对象的数组: Console.log 显示两个对象的数组

I've tried turning the list into another observable since it worked on the initial one but then I get an async pipe issue for some reason.我已经尝试将列表变成另一个可观察的,因为它在最初的一个上工作但后来由于某种原因我得到了一个异步 pipe 问题。

Been struggling with this one for a minute and would like suggestions on how to solve this issue.在这个问题上苦苦挣扎了一分钟,想就如何解决这个问题提出建议。 Any help or ideas is appreciated.任何帮助或想法表示赞赏。

Issue问题

According to What does Angular 2 hashtags in template mean?根据What does Angular 2 hashtags in template mean?

Templates render HTML. In a template you can use data, property binding and event binding.模板呈现 HTML。在模板中,您可以使用数据、属性绑定和事件绑定。 This is accomplished with the following syntax:这是通过以下语法完成的:

# - variable declaration # - 变量声明

This selectedParts variable is conflicted for the HTML and component.selectedParts变量与 HTML 和组件冲突。

Modal HTML模态 HTML

<p-table
    #selectedParts
    [value]="selectedParts"
  >
  ...
</p-table>

Modal Component模态组件

@Input() selectedParts: BasePartFormatted[];

Solution解决方案

Remove #selectedParts from HTML or rename it so that it is not conflicted with selectedParts @Input property.从 HTML 中删除#selectedParts或重命名它,使其与selectedParts @Input属性不冲突。

<p-table
    [value]="selectedParts"
  >
  ...
</p-table>

Sample Solution on StackBlitz StackBlitz 上的示例解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循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' Angular:*ngFor 循环给我错误:找不到类型为“object”的不同支持对象“[object Object]” - Angular: *ngFor loop giving me 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 找不到其他支持对象&#39;[对象对象] - Cannot find a differ supporting object '[object Object] 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 过滤多面阵列,但管道返回错误 - 找不到&#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' 找不到类型为“object”的不同支持对象“[object Object]”。 - 上下文菜单问题 - Cannot find a differ supporting object '[object Object]' of type 'object'. - context menu issues 找不到类型为“数字”的不同支持对象“33.265625” - Cannot find a differ supporting object '33.265625' of type 'number' 在 Angular 上执行 GET 请求时出现此错误:找不到不同的支持 object '[object Object] - Getting this error when doing a GET request on Angular: Cannot find a differ supporting object '[object Object]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM