NullInjectorError:没有 GoogleAnalyticsService 的提供者 - 已修复

问题描述

从 NPM 安装 Ngx 谷歌分析模块后,我在我的应用模块中实现了它,为了自动跟踪,我导入了两个模块,NgxGoogleAnalyticsModuleNgxGoogleAnalyticsRouterModule,我得到了这个错误:>

import { browserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { SharedModule } from "./shared/shared.module";
import { HttpClientModule } from "@angular/common/http";

import {
  NgxGoogleAnalyticsModule,NgxGoogleAnalyticsRouterModule,} from "ngx-google-analytics";

const pages = [];

@NgModule({
  declarations: [AppComponent,pages],imports: [
    AppRoutingModule,browserModule,HttpClientModule,SharedModule,ReactiveFormsModule,browserAnimationsModule,NgxGoogleAnalyticsModule.forRoot(environment.ga),],providers: [],bootstrap: [AppComponent],})
export class AppModule {}

在控制台中 ng serve 后出错:

我的解决方 我试图解决它,我已经通过这种方式修复了它:

在提供者中,我添加了这个服务 >>> GoogleAnalyticsService

@NgModule({
  declarations: [AppComponent,NgxGoogleAnalyticsRouterModule
  ],providers: [
    GoogleAnalyticsService
  ],})
export class AppModule {}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)