I have a class like this.
export class MyClass {
constructor(private http: HttpClient) { }
//rest of class
}
How do I create an object of this class?
I have a class like this.
export class MyClass {
constructor(private http: HttpClient) { }
//rest of class
}
How do I create an object of this class?
As a normal class, e.g.
const object = new MyClass(http); // where http is an injected instance of HttpClient
There is no other simple way doing so. You can also go on a dark side and inject the injector, or worse, assigning injector to some global variable / static property and inject whatever you want via injector directly, like e.g. this is done here Angular 2: Inject service into class; however this is not recommended.