I have a couple of components that are doing the same job. Everyone makes the same API call only with a different parameter:
this.http.get('url' + parameter).subscribe((data: Array<any>) => {
   //some state dispatches and other stuff
   return response;
});
I don´t want to write the same code in every component for reasons. In Java for example I use superclasses for this case. In Angular services are sufficient most of the time. But not in this case.
I tried to write a new class:
export class Content {
   constructor(private http: HttpClient) { }
   getContent() {
     this.http.get('url' + parameter).subscribe((data: Array<any>) => {
       //some state dispatches and other stuff
       return response;
     });      
   }
}
Now I can initialize this class in every component and it works:
export class MyComponent {
  constructor(private http: HttpClient) { }
  toggle() {
    new Content(http);
  }
}
The issue is that I have to use the constructor where I injected the HttpClient. I don´t want that because I have to pass additional dependencies(which are not relevant for the issue).
So is that the best practice and if yes how can I use HttpClient without passing it?
 
     
     
     
     
    