Reputation: 1844
I am injecting service from a super abstract class into our sub classes. This works fine, except for the Store service. What I'm doing is the following:
Super Class:
export abstract class GenericClass {
translate: TranslateService;
cdr: ChangeDetectorRef;
someService: SomeService;
otherService: OtherService;
anotherService: AnotherService;
constructor(injector: Injector){
this.translate = injector.get(TranslateService);
this.cdr = injector.get(ChangeDetectorRef);
this.someService= injector.get(SomeService);
this.otherService = injector.get(OtherService);
this.anotherService= injector.get(AnotherService);
}
}
Sub-Class (Component):
export class SubClassComponent {
constructor(injector: Injector){
super(injector);
}
}
This works fine, but with store it doesn't. When I add Store the same way to the super class, e.g:
Super Class:
export abstract class GenericClass {
...
store: Store<AppState>;
constructor(injector: Injector){
...
this.store = injector.get(Store<AppState>);
}
}
In this case I get the following Error:
ERROR in fox-generic-form.ts(45,30): error TS2348: Value of type 'typeof Store' is not callable. Did you mean to include 'new'?
I tried this with as it suggests in the error:
this.store = injector.get(new Store<AppState>);
How ever in this case I get an error on required arguments in the constructor of Store, and after checking it does require 3 different arguments:
store.d.ts:
constructor(state$: StateObservable, actionsObserver: ActionsSubject, reducerManager: ReducerManager);
I've been searching for this for a while on the net and I can't find a solution, I did find testing scenarios, but those are not what I need for this case of components super-class & Injector.
Any one has an idea of how to use Store with Injector from a super class? Or how I use these 3 arguments (state$: StateObservable, actionsObserver: ActionsSubject, reducerManager: ReducerManager) with Store?
Upvotes: 1
Views: 436
Reputation: 15505
Should work if you would do injector.get(Store)
, without the generic type.
Upvotes: 2