Utilizing an httpmodule to fetch data from the backend, I am faced with a challenge. While loading data in the service and returning it to the component, I also need to send a status code along with it. Unfortunately, the Data
model is already set and cannot be modified.
service
getData(offSet, maxResults): Observable<Data> {
return this.http.get(this.url+"?offset="+offSet+"&maxResults="+maxResults);
}
component
this.dataService.getData(0, this.maxResults).subscribe((data)=>{
this.data = data;
this.total = data.totalCount;
this.pages = Math.ceil(this.total / this.maxResults);
});
I want
In order to obtain the status code within the subscribe callback, my ideal scenario would look something like this:
this.dataService.getData(0, this.maxResults).subscribe((data, status_code)=>{
this.data = data;
this.total = data.totalCount;
this.pages = Math.ceil(this.total / this.maxResults);
});