When getting HTTP response from a REST API using Angular 2.0 HTTP client you will
probably won’t mess around with your request headers.
You’ll probably count on the service to return a JSON formatted response, subscribe
to this response and go ahead using it’s .json() method which will use JSON.parse of
your browser API.
However, while this solution works fine using chrome, Firefox behave differently. While in chrome,
the HTTP Accept headers will be */* , on Firefox it will put text/html,application/xhtml+xml
which basically will cause your server side to return its response in XML form.
Therefore what you need to do is change your Accept headers . You can do so by creating a Headers
type variable. You can do it using this small typescript code snippet below.
Basically what we’ve done here is changing the ‘Accept’ header on our HTTP request and caused our
server side to return JSON. Now, we are all set to work with Firefox as well.
Note: This quick tip is relevant to Angular 2.0 rc1. It may not be relevant in the future where Angular 2.0 is released.