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.

Community
  • 1
  • 1
abrahamlinkedin
  • 467
  • 1
  • 6
  • 23

1 Answers1

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.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720