2016-10-05 4 views
0

JSONP get 호출을 수행하기위한 적절한 방법이 무엇인지 알고 싶습니다. 이 예에서는 see in this link처럼 JSONP url은 myRun 아래에 나열되어 있습니다.Angular 2 Http with jsonp

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) 
    ); 
    } 
} 

나는 examples that useJSONP_PROVIDERS을 본 적이 있지만 나는 그들이 지금까지 사용되지 않습니다 생각합니다. 따라서 JSONP을 요청하기위한 최신 방법이 무엇인지 궁금합니다.

+1

이 게시물 확인 http://stackoverflow.com/questions/36289495/how-to-make-a-simple-jsonp-asynchronous-request-in-angular-2 –

답변

1

링크 된 예와 동일한 내용입니다. 그러나 JSONP_PROVIDERS을 사용하는 대신 HttpModule처럼 JsonpModule을 가져올 수 있습니다. 그런 다음 your linked example처럼 Jsonp을 삽입하십시오. 사용법은 변경되지 않았습니다. 앞서 언급 한 클래스의

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

모든 또한 @angular/http에서 가져올 수 있습니다.