当提供者列表中确实存在'时,Angular为什么不抛出任何提供者?

时间:2019-05-18 02:49:19

标签: 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起作用之前加载的?

0 个答案:

没有答案