0

I would like to know what's the appropriate method for perfoming a JSONP get call. In this instance, my JSONP url is listed under myRun as you can see in this link.

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';

@Injectable()
export class AppService {
constructor(private http: Http){}
    fetchData(){
    return this.http.get('http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=myRun').map(
        (res) => res.json()
        ).subscribe(
        (data) => console.log(data)
    );
    }
}

I've seen examples that use JSONP_PROVIDERS, but I believe they are deprecated by now. Thus, I am wondering what the up-to-date method is for making a JSONP get request.

1

1 Answer 1

1

It's still the same thing as in the examples you linked to. But instead of using the JSONP_PROVIDERS, you import the JsonpModule just like you would the HttpModule. Then just inject Jsonp, like in your linked example. It's usage hasn't changed.

export class AppComponent {
  constructor(jsonp:Jsonp) {
    var url = 'https://accounts.google.com/logout&c=JSONP_CALLBACK';
    jsonp.request(url, { method: 'Get' })
     .subscribe((res) => {
       (...)
     });
  }
}

All of the previously mentioned classes can be also imported from @angular/http.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.