Angular no overload matches this call
14,398
From docs: However, with some libraries it may be necessary to manually encode the "user:key" in base64 and send the result in the "Authorization" header as part of each HTTP request
var fxml_url = 'http://flightxml.flightaware.com/json/FlightXML2/';
var username = 'YOUR_USERNAME';
var apiKey = 'YOUR_APIKEY';
var auth = btoa(`${username}:${apiKey}`);
this.http.get(fxml_url + 'MetarEx', {
headers: { Authorization: auth },
params: new HttpParams({fromObject: { airport: 'KAUS', howMany: '1' }})
}).subscribe(data=>{
console.log(data)
});
Related videos on Youtube
Author by
Ali Ghassan
Updated on June 04, 2022Comments
-
Ali Ghassan almost 2 years
l am try to get data Json api from flightaware using Angular . And all requests from flightaware must include a username and FlightXML Key using basic HTTP Authentication standard .
Code
var fxml_url = 'http://flightxml.flightaware.com/json/FlightXML2/'; var username = 'YOUR_USERNAME'; var apiKey = 'YOUR_APIKEY'; this.http.get(fxml_url + 'MetarEx', { username: username, password: apiKey, query: {airport: 'KAUS', howMany: 1} }).subscribe(data=>{ console.log(data) })
but l get error is
No overload matches this call. The last overload gave the following error. Argument of type '{ username: string; password: string; query: { airport: string; howMany: number; }; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'. Object literal may only specify known properties, and 'username' does not exist in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
any idea please ?
-
Ali Ghassan over 4 yearsThank you brother for asnwering . but i have error under
params
andAccess to XMLHttpRequest at 'http://flightxml.flightaware.com/json/FlightXML2/MetarEx
. -
joyBlanks over 4 yearstry now. just had to put params this way, mostly i put them in the url itself when its a get request