I have a service like this
@Injectable()
export class MyService {
constructor(private store: Store, @Optional() type: string){}
static forType(type: string) {
return { provide: MyService, deps: [Store], useFactory: factoryFn.bind(type) }
}
}
export function factoryFn(store: Store, type: string) {
return new MyService(store, type);
}
and want to inject it into my component like this
@Component{
providers: [MyService.forType('hello')]
}
export class MyComponent {}
but this gives me following error
Function calls are not supported in decorators but 'factoryFn' was called in 'MyService'
'MyService' calls 'factoryFn'.
The reason that I want to have it as a static method on the actual service is, because I don't want the component to know which dependencies MyService needs. MyService is also used at many different places, so with this way, I also avoid duplications.
Is there a way to trick Angular into allowing the function call?
Best regards, Benedikt