[英]Angular Static Injector Provider error - but only when extending another injectable
我有一個基於API的服務,看起來像這樣
@Injectable()
export class ApiBaseService {
constructor(
private http: HttpClient,
_configuration: ConfigurationService
) {
this.apiUrl = _configuration.serverWithApiUrl;
}
}
我正在嘗試將其擴展為如下所示:
@Injectable()
export class StaticTranslationService extends ApiBaseService {
private staticTranslations = new ReplaySubject(1);
constructor(
http: HttpClient,
_configuration: ConfigurationService
) {
super(http, _configuration);
this.staticTranslations.next(json);
}
}
但是我得到這個錯誤:
StaticInjectorError(AppModule)[StaticTranslationService -> ConfigurationService]:
StaticInjectorError(Platform: core)[StaticTranslationService -> ConfigurationService]:
NullInjectorError: No provider for ConfigurationService!
但是,我的app.module提供程序如下所示:
providers: [
ConfigurationService,
ApiBaseService,
StaticTranslationService
]
ConfigurationService可以注入到其他服務中,這些服務也可以擴展ApiBaseService並在那里工作-但是它們沒有自己的構造函數,這是唯一的區別。
有人知道這里的問題嗎?
您應該在這里創建一個抽象類ApiBaseService,然后將其擴展到其他Injectable Services中。 基本服務不應標記為可注入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.