When using Angular2 (RC4), I utilize this code snippet to retrieve data from my WebApi:
getAppointment(id: number): Observable<Event> {
return this._http.get(this._serviceUrl + 'get/' + id)
.map(this.extractData)
.catch(this.handleError);
}
The function this.extractData looks like this:
private extractData(res: Response) {
let body = res.json();
return body || {};
}
Everything works fine in Chrome, IE, Edge, but when it comes to Mozilla, it throws this error:
JSON.parse: unexpected character at line 1 column 1 of the JSON data
This issue seems to be related to the @angluar2/http module static_response.d.ts file.
/**
* Attempts to return body as parsed `JSON` object, or raises an exception.
*/
json(): any;
And in the static_response.d.js file:
/**
* Attempts to return body as parsed `JSON` object, or raises an exception.
*/
Response.prototype.json = function () {
var jsonResponse;
if (http_utils_1.isJsObject(this._body)) {
jsonResponse = this._body;
}
else if (lang_1.isString(this._body)) {
jsonResponse = lang_1.Json.parse(this._body);
}
return jsonResponse;
};
Why does this fail in Mozilla? Could it be a bug in @angular2/http?