I have successfully set up a backend API, and I can confirm that it is functioning properly based on the POSTMAN screenshot provided https://i.sstatic.net/pIl4k.png
Below is a snippet of my service code:
getComments(line: string, department: string, startTime?: number, endTime?: number): Observable<Array<IComments>> {
let headers = new Headers(
{
'Content-Type': 'application/x-www-form-urlencoded',
'line': line,
'cell': department,
'start': new Date(),
'end': ago(24, "hours")
});
let options = new RequestOptions({ headers: headers });
return this.http.get('api/data/comments', options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body.data || {};
}
Furthermore, here is an excerpt from my component:
this.dataService.getComments('604', 'powders').forEach(result => {
console.log('Res: ' + JSON.stringify(result));
that.comments = result;
});
Despite having implemented the above code, the console output only shows:
Res: {}
This discrepancy raises the question as to why the expected data is not being returned in the same manner as shown in postman.
Update:
Upon adding console.log(body)
within the extractData function, I received the following output:
Object {result: "COMMENTS604"}