title: Angular: How to send a string to an injection service?
body: <p>i created generic service to crud task, the service use the HttpClient by DI (Dependency Injection), but i need to inform another value in the constructor of the service, how to make this?</p>
  
  <p>because when I define that in the constructor of my class that will consume the CRUD service using DI, there is no way to pass the parameter to the constructor</p>
  
  <p>below is the service</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Injectable } from "@angular/core";
  import { HttpClient } from "@angular/common/http";
  import { CrudInterface } from "@app/core/crud.interface";
  import { environment } from "@env/environment";
  import { Observable } from "rxjs/Observable";
  
  @Injectable()
  export class CRUD&lt;T&gt; implements CrudInterface&lt;T&gt;{
      
      endpoint: string;
  
      constructor(private http: HttpClient, routeDir: string){
          this.endpoint = `${environment.endpoint}/${routeDir}`;
      }
      
      getAll(): Observable&lt;T[]&gt; {
          return this.http.get&lt;T[]&gt;(`${this.endpoint}`);
      }
  
      get(id: number): Observable&lt;T&gt; {
          return this.http.get&lt;T&gt;(`${this.endpoint}/${id}`);
      }
  
      create(object: T): Observable&lt;T&gt; {
          return this.http.post&lt;T&gt;(`${this.endpoint}`, object);
      }
  
      update(object: T): Observable&lt;T&gt; {
          return this.http.put&lt;T&gt;(`${this.endpoint}`, object);
      }
  
      delete(id: number): Observable&lt;any&gt; {
          return this.http.delete&lt;T&gt;(`${this.endpoint}/${id}`);
      }
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Usuario } from "@app/usuarios/model/usuario";
  import { CRUD } from "@app/core/crud.service";
  
  class TestCrudServide {
  
      constructor(
          /**
           * How to inform the parameter here?
           * in this case the endpoint (2nd parameter of the CRUD service)
           */
          private crudService: CRUD&lt;Usuario&gt;
      ){ }
  
      getAll(){
          this.crudService.getAll();
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <h2>UPDATE</h2>
  
  <p>utilizing a solution proposed by Sannon Aragão (thanks) of the concept of factories, i created the service provider for create the instance dynamically</p>
  
  <p><a href="https://angular.io/guide/dependency-injection#factory-providers" rel="noreferrer">https://angular.io/guide/dependency-injection#factory-providers</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export class crudServiceProvider {
  
      static getProvider(routeDir: string) {
          return {
              provide: CRUD,
              deps: [HttpClient],
              useFactory: (dep) =&gt; {
                  return new CRUD(dep, routeDir);
              }
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>and in my component</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Component({
    selector: 'app-revenda',
    templateUrl: './revenda.component.html',
    styleUrls: ['./revenda.component.css'],
    providers:[ crudServiceProvider.getProvider('/api/revenda') ]
  })
  export class RevendaComponent implements OnInit {
  
    constructor(
        private crudService: CRUD&lt;Revenda&gt;
      ) { }
      
      ngOnInit() {
        // now it's work with the correct path and type!
        this.crudService.get(1).subscribe(item =&gt; console.log(item));
      }
  }</code></pre>
  </div>
  </div>
  </p>