I need help with how I can inject a service into another service that I have. Here is the setting:
this is my main.ts where I bootstrapModule:
platformBrowserDynamic()
.bootstrapModule(DTIframeModule, {
preserveWhitespaces: false
}).then((ngModuleRef: NgModuleRef<DTIframeModule>) => {
const rootInjector = ngModuleRef.injector;
const instrumentationService = rootInjector.get(InstrumentationService);
if (instrumentationService instanceof DTService) {
const routeService = rootInjector.get(DTRouteService);
instrumentationService.registerDTRouteService(routeService);
}
}
and this the detail of InstrumentationService and DTService:
@Injectable()
export abstract class InstrumentationService {
public abstract generateDTEvent(
eventName: string,
params?: Params): InstrumentationEvent;
}
@Injectable()
export class DTService implements InstrumentationService {
private queuedEventsPopulatedWithRoute: boolean;
// few other fields
public registerRouteService(routeService: RouteService) {
// some function
}
public generateDTEvent(
eventName: string,
params?: Params): InstrumentationEvent {
// some service
}
}
What I have issues with is that I would like to use a service called WinService inside DTService, I added the import:
import { WinService } from '../services/win.service';
and wanted to access it inside DTService like this:
this.winService.native.events;
But however I tried I am hitting the wall and getting error that this.winService is undefined. I tried adding a constructor to DTService and add private readonly winService: WinService and it is throwing injection error.
Any help would be very much appreciated. Thanks!
WinServicein theprovidersarray of the module?WinServicelook like? How does your constructor ofDTServicelook like when you import it?