keepwalking
keepwalking

Reputation: 2654

Angular 2 - Inject provider in class (typescript)

Not sure what is the best option but here it goes.

I have the following class

export class Order {
    number?: any;
    api?: ApiRequest;
    constructor(number, api: ApiRequest) {
      this.number = number;
      this.api = api;
    }
}

When i create the order i use the following

let order new Order(123, this.request);

ApiRequest is an injectable global provider.

Is there a way i can automatically inject the api provider in the class when i create a new object?

Upvotes: 1

Views: 547

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657158

No. Injecting only works for instances that are created by DI, not if you create one yourself with new Xxx().

Upvotes: 1

Related Questions