简体   繁体   English

错误:InvalidPipeArgument:primeng 表中管道“SlicePipe”的“[object Object]”

[英]Error: InvalidPipeArgument: '[object Object]' for pipe 'SlicePipe' in primeng table

I have a component in angular to return data from BE and show it in p-table我有一个 angular 组件来从 BE 返回数据并将其显示在p-table

Here is html of component这是组件的html

<p-table [value]="filteredRestaurants" [paginator]="true" [rows]="10">
  <ng-template pTemplate="header">
    <tr>
      <th>Name</th>
      <th>Address</th>
      <th>Cuisine Types</th>
      <th>Rating</th>
      <th>Avialability</th>
    </tr>
  </ng-template>
  <ng-template pTemplate="body" let-restaurant>
    <tr>
      <td>{{ restaurant.name }}</td>
      <td>{{ restaurant.adress.city }}</td>
      <td></td>
      <td>{{ restaurant.starRating }}</td>
      <td></td>
    </tr>
  </ng-template>
</p-table>

and here is how I realize component logic这是我如何实现组件逻辑

  export class AppComponent {
  postCodes: any[] = [];
  selectedPostCode: string;
  filteredRestaurants: any;
  constructor(private mapboxService: MapboxService, private http: HttpClient) {}
  title = 'just-eat-angular';
  headers = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json',
    }),
  };
getResults() {
    return this.http
      .post(
        environment.baseUrl + '/PostCodeSearch/GetRestaurantsByPostCode',
        JSON.stringify(this.selectedPostCode),
        this.headers
      )
      .subscribe((r) => {
        console.log(r);
        this.filteredRestaurants = r;
      });
  }
}

When I click the button, I need to get data from BE当我点击按钮时,我需要从 BE 获取数据

In the console, I got this在控制台中,我得到了这个在此处输入图片说明

And in this error在这个错误中

core.js:4197 ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'SlicePipe' at invalidPipeArgumentError (common.js:4152) at SlicePipe.transform (common.js:5154) at Module.ɵɵpipeBind3 (core.js:24715) at TableBody_ng_container_0_Template (primeng-table.js:167) at executeTemplate (core.js:7303) at refreshView (core.js:7172) at refreshEmbeddedViews (core.js:8280) at refreshView (core.js:7196) at refreshComponent (core.js:8326) at refreshChildComponents (core.js:6965) core.js:4197 错误错误:InvalidPipeArgument: '[object Object]' for pipe 'SlicePipe' at invalidPipeArgumentError (common.js:4152) at SlicePipe.transform (common.js:5154) at Module.ɵɵpipeBind3 (core.js: 24715) at TableBody_ng_container_0_Template (primeng-table.js:167) at executeTemplate (core.js:7303) at refreshView (core.js:7172) at refreshEmbeddedViews (core.js:8280) at refreshView (core.js:7196) at refreshComponent (core.js:8326) at refreshChildComponents (core.js:6965)

How I can fix this?我该如何解决这个问题?

Prime Table expects an array and you give it an Object. Prime Table 需要一个数组,你给它一个对象。 I believe you should have我相信你应该有

this.filteredRestaurants = r.restaurants;

暂无
暂无

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

相关问题 ionic3-错误错误:未捕获(承诺):错误:InvalidPipeArgument:管道“ AsyncPipe”的“ [object Object]” - ionic3 - ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' InvalidPipeArgument:管道“ AsyncPipe”的“ [object Object]”,无法修改HTML - InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe', cannot modify HTML InvalidPipeArgument:管道“ AsyncPipe”的“ [object Object]”,但控制台提供了Observable吗? - InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' but console gives Observable? InvalidPipeArgument:&#39;[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象], - InvalidPipeArgument: '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], ERROR 错误:InvalidPipeArgument:pipe 'DatePipe' 的“12-01-2020 - 12-02-2020' to a date' - ERROR Error: InvalidPipeArgument: "12-01-2020 - 12-02-2020' to a date' for pipe 'DatePipe' Component.html:151 错误错误:InvalidPipeArgument:'无法将 pipe'DatePipe' 的“14-05-2021”转换为日期' - Component.html:151 ERROR Error: InvalidPipeArgument: 'Unable to convert “14-05-2021” into a date' for pipe 'DatePipe' &#39;[object Object],[object Object]&#39; 用于管道 &#39;AsyncPipe&#39; - '[object Object],[object Object]' for pipe 'AsyncPipe' DataTable中的primeNg复选框绑定对象 - primeNg Checkbox binding object in Datatable 在primeng的列中显示嵌套对象 - Display nested object in column in primeng 在服务器API返回的对象中使用PrimeNG数据表绑定和使用对象的字段 - Binding and using an object's fields within an object returned by the server API with a PrimeNG data table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM