Angular 7, p-table Primeng: Error: Invalidpipeargument: '[Object Object]' for pipe 'Slicepipe'

Asked

Viewed 1,129 times

1

I am trying to make a list in a "p-table" of primeng, until yesterday I was listing everything perfectly, but today when running the angular project I noticed that this error was occurring. I have no idea what it means, let alone why, because everything was working normally.

Error:

TableBody.html:8 ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'SlicePipe'
at invalidPipeArgumentError (common.js:4323)
at SlicePipe.push../node_modules/@angular/common/fesm5/common.js.SlicePipe.transform (common.js:5812)
at Object.eval [as updateDirectives] (TableBody.html:8)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911)
at checkAndUpdateView (core.js:23307)
at callViewAction (core.js:23548)
at execEmbeddedViewsAction (core.js:23511)
at checkAndUpdateView (core.js:23308)
at callViewAction (core.js:23548)
at execComponentViewsAction (core.js:23490)

Tablebody.html line 8: (where the error occurs. Obs: I never entered this file)

<ng-template ngFor let-rowData let-rowIndex="index" [ngForOf]="(dt.paginator && !dt.lazy) ? ((dt.filteredValue||dt.value) | slice:dt.first:(dt.first + dt.rows)) : (dt.filteredValue||dt.value)" [ngForTrackBy]="dt.rowTrackBy">

The code of my table.html and component.ts: (Obs: the GET method is working normally by returning all data, I have tested it separately and the problem occurs when data falls into the table.) Code available in codeshare

1 answer

3


I went through the same problem with Angular 7 and Primeng.

In my case, I was receiving an observable object containing within it an array with the GET request data in the back-end.

To iterate in the Primeng table you need an Array.

Thus, it was necessary to search within the object the array with the data and store in the variable inside the component.

//função get dentro do service.ts
return this.http
           .get<any[]>(`${this.url}`)
           .pipe(
                 map(res => res['content']) //pegando o array no HttpResponse
           );

Then, in the component, stores the array in the variable and iterates over it to display.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.