I am attempting to retrieve the response from my POST request using Angular 4. Below is the code I am using:
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);
}
);
Service.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'));
}
The POST request is successfully retrieving all required data (headers, response, etc.), but I am facing difficulty in utilizing those values within my components. How can I access and utilize them?
I need to populate:
agreementList: Agreement[];
with the retrieved response.
Apologies for any confusion caused, please let me know if you require further information.
EDIT:This is the response I am receiving
Edit2:
Component.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'));}