2

I believe I'm just doing something wrong here, but for some reason, my http.get() request always throws an error.

Here's an excerpt of my code:

import {Http, Response, Headers} from '@angular/http';
import 'rxjs/Rx';
...
export class CustomClass{
  ...
  getAPI(){
    this.http.get('http://ip-api.com/json')
      .map((res: Response) => {
        res.json();
      })
      .subscribe(
        (data) => console.log(data),
        (error) => console.error(error),
        () => console.log(this)
      );
  }
}

I'm under the impression that this code block should simple get the response form http://ip-api.com/json and then output it. However, the only result I ever get is the error response and I can't figure out why.

0

1 Answer 1

1

The code is correct, check the Network tab in the Browser developing tools and see why the http request fails.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.