【发布时间】:2019-01-11 02:48:46
【问题描述】:
我正在尝试从我的帖子中获取角度为 4 的响应。这是我的代码:
app.component.html:
`findAccordiSmall(pagination: Pagination) {
this.accordiListTableLoading = true;
debugger;
this.accordiService.findAccordiSmall(pagination).subscribe(
(res: HttpResponse<any>) => {
res.headers.get('offset');
res.headers.get('count');
this.agreementList= res.body;
} errors => {
this.accordiListTableLoading = false;
Utils.notifyErrors(errors, this.notificationsService);
}
);
服务.ts
findAccordiSmall(pagination: Pagination): Observable<HttpResponse<any>> {
const queryParams = this.getHttpParams(pagination).toString();
return this.http.post(`${this.ENDPOINT}/agreements-paginated?${queryParams}`,pagination, { observe: 'response' })
.catch(error => Utils.handleError(error, this.router, 'Errore nel recupero delle pratiche'));
}
POST 正在向我发送我想要的所有数据(标题、响应等),但我无法在我的组件中使用这些值。我怎么称呼他们?
我必须填写:
agreementList: Agreement[]; 回复。
抱歉,如果您需要更多信息,请告诉我。
编辑2:
组件.ts
findAccordiSmall(pagination: Pagination) {
this.accordiListTableLoading = true;
this.accordiService.findAccordiSmall(pagination).subscribe(
(res: Agreement[]) => {
this.agreementList= res;
},
errors => {
this.accordiListTableLoading = false;
Utils.notifyErrors(errors, this.notificationsService);
}
);
service.ts
findAccordiSmall(pagination: Pagination): Observable<Agreement[]> {
const queryParams = this.getHttpParams(pagination).toString();
debugger;
return this.http.post<Agreement[]>(`${this.ENDPOINT}/agreements-paginated?${queryParams}`,pagination, { observe: 'response' })
.map(res => res)
.catch(error => Utils.handleError(error, this.router, 'Errore nel recupero delle pratiche'));}
【问题讨论】:
-
你使用HttpClient还是Http?
-
你能说明你收到了什么回复吗?
-
我正在使用 HttpClient
标签: angular typescript httpresponse