In Angular, I have a http service that I need to return a promise from because the library I am using relies on a promise based http client. However, the error ERROR Error: Uncaught (in promise): TypeError: this is undefined
occurs in my code whenever this http service is called.
For example the http service is being called in this other service by a simple:
const destinyManifest = getDestinyManifest(this.http.$fetch)
and the http client code looks like:
export class APIHTTPService {
constructor(private http: HttpClient) {}
$fetch(config: HttpClientConfig) {
const httpOptions = {
headers: new HttpHeaders({
'X-API-KEY': environment.bungieAPIKey,
}),
params: new HttpParams(config.params),
}
let promise = new Promise<any>((resolve, reject) => {
this.http
.get(config.url, httpOptions)
.toPromise()
.then((response) => {
resolve(response)
console.log('response')
})
})
return promise
}
}