title: Same Code in Multiple Components Angular 6
body: <p>I have a couple of components that are doing the same job.
  Everyone makes the same API call only with a different parameter:</p>
  <pre class="lang-ts prettyprint-override"><code>this.http.get('url' + parameter).subscribe((data: Array&lt;any&gt;) =&gt; {
     //some state dispatches and other stuff
     return response;
  });
  </code></pre>
  <p>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.</p>
  <p>I tried to write a new class:</p>
  <pre class="lang-ts prettyprint-override"><code>export class Content {
     constructor(private http: HttpClient) { }
     getContent() {
       this.http.get('url' + parameter).subscribe((data: Array&lt;any&gt;) =&gt; {
         //some state dispatches and other stuff
         return response;
       });      
     }
  }
  </code></pre>
  <p>Now I can initialize this class in every component and it works:</p>
  <pre class="lang-ts prettyprint-override"><code>export class MyComponent {
    constructor(private http: HttpClient) { }
    toggle() {
      new Content(http);
    }
  }
  </code></pre>
  <p>The issue is that I have to use the constructor where I injected the <code>HttpClient</code>. I don´t want that because I have to pass additional dependencies(which are not relevant for the issue).</p>
  <p>So is that the best practice and if yes how can I use <code>HttpClient</code> without passing it?</p>