Based on this example for Http, I would like to know how to instantiate HttpClient:
**constructor() {
const browserXhr: BrowserXhr = new BrowserXhr();
const baseResponseOptions: ResponseOptions = new ResponseOptions();
const xsrfStrategy: CookieXSRFStrategy = new CookieXSRFStrategy();
const backend: XHRBackend = new XHRBackend(browserXhr, baseResponseOptions, xsrfStrategy);
const requestOptions: RequestOptions = new RequestOptions();
const http: Http = new Http(backend, requestOptions);
this._http = http;**
So I would like to know how to instantiate HttpClient this way.
I have a class and I have a class parameter.
More current considerations ...
I need to create a class that when instantiated I will tell the name of the table that it will work but I do not want to have the need to enter more parameters in the class constructor as I have to do currently as this example below (this is how it works now ):
@Injectable()
export class MvsDbTable implements OnInit {
constructor(
@Inject('_tableName') public _tableName: string,
@Inject('_HTTP') public _HTTP: HttpClient ) {}
Then I instantiate the class in a service:
public _tblFinances = new MvsDbTable('Finances', this._Http);
But I would like to not have to report this parameter, "this.http".
So I'd like it to look like this:
@Injectable()
export class MvsDbTable implements OnInit {
constructor(
@Inject('_tableName') public _tableName: string ) {
this._HTTP = new HttpClient(this._Handler); }
It just does not work to instantiate the _Handler parameter because it is abstract so it can not be instantiated.
So I would instantiate the class in a service like this:
public _tblFinances = new MvsDbTable('Finances');
Just the code is cleaner, the first form already works. What I try to figure out is how to instantiate the HttpClient inside the class without having to pass the HttpClient as a parameter in the constructor as I did with the Http that also worked.
Thank you