Köşeli 2 - Bir Http sözünü nasıl yazarım?Köşeli 2 - Başlığımda bir Http sözünü nasıl yazarım
http'yi içe aktarıyorum ve http başlığını auth jetonumla ayarlamak istiyorum. O zaman bir http almak istiyorum ve cevabı, buna cevap veren yönteme dönmek için bir söz vermek istiyorum.
Şimdiye kadar bu var:
import {Http, Headers} from "angular2/http";
import {EnvironmentService} from './environmentService';
export class AuthService {
private environmentService: EnvironmentService;
private http: Http;
private header: Headers;
contructor(_environmentService: EnvironmentService, _http: Http, _header: Headers){
this.environmentService = _environmentService;
this.http = _http;
this.header.append('Authorization', '1234');
this.header.append('Content-Type', 'application/json');
}
getSpotifyData =():Promise<Object> => {
return this.http
.get('http://ws.spotify.com/search/1/track.json?q=foo', {headers:this.header})
.map((response) => {
return response.json()
})
.toPromise();
}
}
peşin!
Daha iyi anlaşılması için Kodu göster –
Kod sadece – AngularM