i would like to inject an existing generic service into an custom RXJS Operator, but receive every time only a new instance. And the new instance is for me useless. I could pass the service as a parameter. However, I find that ugly
What must i do, to inject an existing generic service instance?
The Service
@Injectable({providedIn: 'root'})
export class FormService<T> {
public obs$: Subject<T> = new Subject<T>();
constructor() {}
}
the example Operator
export const DatasetUpdateOperator = <T>(propertyKey: string) => (source$) => {
const inject = Injector.create({
providers: [{
provide: FormService,
useFactory: () => (new FormService<T>())
}]
});
inject.get<FormService<T>>(FormService).obs$.subscribe((output) => {
console.log(output);
});
return new Observable(...);
}
The Module
@NgModule({
declarations: [...],
exports: [...],
providers: [
FormService
],
imports: [...]
})