Lyokolux
Lyokolux

Reputation: 1417

Instantiating an HttpClient object in abstract class

I am currently creating an abstract class that every service can inherit from. I try to instantiate the HttpClient in the abstract class but an argument is needed. Which one (what type, ...)?

I don't want to repeat it in constructor of inherited classes. That's why I am trying to do so.

import { HttpClient } from '@angular/common/http';

export abstract class GenericService<T> {
  //... code ...

  constructor() {
    this._http = new HttpClient(); // Argument needed ?
  }

  //... code ...
}

Upvotes: 2

Views: 531

Answers (1)

Raphael Castro
Raphael Castro

Reputation: 1148

Try this

import { HttpClient } from '@angular/common/http';

export abstract class GenericService<T> {
  //... code ...

  constructor(private _http: HttpClient) {}

  //... code ...
}

Upvotes: 2

Related Questions