I'm struggling to utilize my ApiService class, which handles API requests, in another class. Unfortunately, I am encountering a roadblock as the constructor for ApiService requires an HttpClient parameter. This means I can't simply create a new instance like this: `http = new ApiService(new HttpClient(), globals)`
ApiService:
import { Injectable } from '@angular/core';
import { HttpClient, HttpRequest } from '@angular/common/http';
import { Globals } from './globals';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient, private globals: Globals) {}
get(url : string, params: {}){
return this.http.get(this.globals.api_url.concat(url), {params: params});
}
...
}
Class invoking ApiService:
export class UploadAdapter {
http: ApiService;
constructor() {}
upload() {
//Encountering an error here stating "cannot read property 'post' of undefined"
http.post('api_url'.concat('/medias/upload'), {}, {})
.subscribe((data) => {
//do stuff here.
});
}
}