I know I can inject store inside a component constructor like this :
constructor(private store:Store){
store.select('thing').subscribe(
()=>{
console.log('do my thing'); // Got the thing
}
);
}
But I want to create a decorator to be able to use this select inside it , so I want to inject Store inside my decorator :
export function Select<T> ( selector ) {
return function decorate ( target : any , key : string ) : void {
let injector = ReflectiveInjector.resolveAndCreate( [
StoreModule.provideStore(()=>{} , {}).providers
] );
let store = injector.get( Store );
store.select( 'thing' ).subscribe( ()=> {
console.log( 'do my thing',thing ); // thing is undefined
} );
}
}
Weird thing is Store is not an Injectable class( looking at the source code ) and it needs 3 property to be passed to be able to instantiate it ( Reducers , State and one more ).
So how does Angular itself can inject that class in constructor, without providing those arguments , but when I'm trying to inject , it needs them?
I've literally tried all the different Injector and ReflectiveInjector methods , none of them works for me .