我有一个角的组件,可以从BE返回数据并在p-table
中显示它。
以下是组件的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>
下面是我如何实现组件逻辑的方法
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;
});
}
}
当我单击按钮时,我需要从BE获取数据。
在控制台里,我拿到了这个
在这个错误中
core.js:4197错误: InvalidPipeArgument:管道'SlicePipe‘在invalidPipeArgumentError (common.js:4152) at SlicePipe.transform (common.js:5154)处为'object Object’(core.js:24715) at TableBody_ng_container__Template (primeng-table.js:167) at executeTemplate (core.js:7303) at refreshEmbeddedViews (core.js:8280) at refreshView (core.js:8280) at refreshView () at ()
我怎么才能解决这个问题?
发布于 2020-09-02 10:07:13
Prime需要一个数组,然后给它一个对象。我相信你应该
this.filteredRestaurants = r.restaurants;
https://stackoverflow.com/questions/63703222
复制相似问题