angular - 为什么 Angular 在提供者列表中确实存在“”时不抛出任何提供者?
问题描述
我有以下可注射服务
import { ConfigService } from './app-config.service';
import { Injectable, OnInit, Inject } from '@angular/core';
import { AppInsights } from 'applicationinsights-js';
@Injectable()
export class AppInsightsService {
appInsightsInstrumentationKey: string;
private config: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: this.appInsightsInstrumentationKey
}
constructor (private configService: ConfigService){
this.configService = configService;
this.appInsightsInstrumentationKey =
configService.config.appInsightsInstumentationKey;
if (!AppInsights.config) {
AppInsights.downloadAndSetup(this.config);
}
}
logPageView(name?: string, url?: string, properties?: any, measurements?: any, duration?: number) {
AppInsights.trackPageView(name, url, properties, measurements, duration);
}
logEvent(name: string, properties?: any, measurements?: any) {
AppInsights.trackEvent(name, properties, measurements);
}
}
ConfigService 在 app.module 的提供者列表中(实际上它被注入到其他类中就好了)
providers: [
LoaderService,
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [ConfigService],
multi: true
},
DaterangepickerConfig,
TriggerEventAssignmentComponent,
TimelineSummaryComponent,
AlternateTemplateService,
SelectedTriggerService,
RouteHistoryService,
AppInsightsService
],
将配置服务注入 AppInsightsService 但是我收到错误:
错误:没有 ConfigService 的提供者!(AppInsightsService -> ConfigService)
AppInsightsService 被注入到 app.component 构造函数中。
我无法注射到注射剂中还是这里发生了其他事情?
更新:我尝试添加到此 AppInsightsService 的构造函数中的任何内容都得到了这个。我试过像'Http'这样的东西,我得到同样的错误,说没有HTTP提供者。所以这与 AppInsightsSerivce 如何在角度中使用以及何时加载有关。我怀疑它在 App.Module 之前被加载了它的工作吗?
解决方案
推荐阅读
- php - 数组中的正确图像路径
- salesforce - SingleEmailMessage 和 cc 的问题
- css - 如何并排放置 2 个图像而它们之间没有空格?
- reactjs - 如何使用 .NET Core 与 redux 项目反应基于反应组件修改页面标题?
- javascript - IE 11 上的 MutationObserver 语法错误
- c# - 同一实体类型的一对一和一对多
- r - 更改分组条形图中的条形颜色
- c++ - 选择派生实例基类专用的类模板
- c# - 用于计算着色器步幅的自定义结构的 sizeof
- css - 将 Css 表单与页面中心对齐(是的,我查看了其他答案,我无法让它工作)