0

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?

reika
  • 526
  • 5
  • 14
  • 1
    The question cannot gain a quality answer because it lacks the context. Where exactly do you need to create an object and why did you not use DI to do that? – Estus Flask Jan 06 '18 at 23:59

1 Answers1

0

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.

smnbbrv
  • 23,502
  • 9
  • 78
  • 109