In Angular, I have a service that has few things injected through the constructor(...)
. However that service is also at some place created by calling the constructor. Therefore, adding another service it depends on to the parameters would change the API. I'd like to avoid that.
Is there a way to inject a service into another service without adding it to the constructor parameters? E.g. field injection?
import {Inject, Injectable} from "@angular/core";
import {
Http, Request, ConnectionBackend, RequestOptions, RequestOptionsArgs, Response, Headers,
RequestMethod
} from "@angular/http";
import {KeycloakService} from "./keycloak.service";
import {Observable} from 'rxjs/Observable';
import {EventBusService} from "../events/event-bus.service";
import {LoadingSomethingFinishedEvent, LoadingSomethingStartedEvent} from "../events/windup-event";
@Injectable()
export class WindupHttpService extends Http {
constructor(
_backend: ConnectionBackend,
_defaultOptions: RequestOptions,
private _keycloakService: KeycloakService,
// ----- This is what I want to avoid. -----
private _eventBus: EventBusService,
) {
super(_backend, _defaultOptions);
}
// ------- This is what I am looking for ---------
//@Inject()
//private _eventBus: EventBusService;