D
D
Dmitry2017-08-13 23:27:57
JavaScript
Dmitry, 2017-08-13 23:27:57

How to rewrite jquery code in angular2?

Hello.
I need to rewrite the request code from jquery to angular2.
There is a code:

$.get("https://ipinfo.io", function(response) {
  console.log(response.ip, response.country);
}, "jsonp")

I rewrote it like this:
public getLocationUser() {
    let headers = new Headers({ 'Content-Type': 'application/json'}); //../jsonp
    let options = new RequerstOptions({ headers: headers })
    return this.http.get("https://ipinfo.io", options).map(location => location.json())
      .subscribe((loc) => loc)
  }

Through jquery data comes in json format!
And through the getLocationUser() method - as text!
How to fix it ?!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question