在 Angular 中,我有一个服务,通过constructor(...). 然而,该服务也是在某个地方通过调用构造函数创建的。因此,在参数中添加它所依赖的另一个服务将会改变 API。我想避免这种情况。
有没有办法将一个服务注入另一个服务而不将其添加到构造函数参数中?例如现场注入?
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 …Run Code Online (Sandbox Code Playgroud)