简体   繁体   English

Angular2:例外:没有 Angulartics2GoogleAnalytics 的提供者

[英]Angular2 : EXCEPTION: No provider for Angulartics2GoogleAnalytics

I am trying to use angulartics2 with my application.我正在尝试在我的应用程序中使用angulartics2

I have configured correctly as it mentioned in the document.我已按照文档中提到的正确配置。

Note: There is no place it is mentioned to add the provider as a dependency..注意:没有提到将提供程序添加为依赖项的地方。

When i try to run the application, it shows the error as below.当我尝试运行该应用程序时,它显示如下错误。

EXCEPTION: No provider for Angulartics2GoogleAnalytics!例外:没有 Angulartics2GoogleAnalytics 的提供者! Error: DI Error at NoProviderError.ZoneAwareError (zone.js:811) at NoProviderError.BaseError [as constructor] (core.umd.js:1186) at NoProviderError.AbstractProviderError [as constructor] (core.umd.js:1371) at new NoProviderError (core.umd.js:1411) at ReflectiveInjector_.错误: NoProviderError.ZoneAwareError (zone.js:811) at NoProviderError.BaseError [as constructor] (core.umd.js:1186) at NoProviderError.AbstractProviderError [as constructor] (core.umd.js:1371) 处的DI错误ReflectiveInjector_ 上的新 NoProviderError (core.umd.js:1411)。 throwOrNull (core.umd.js:3394) at ReflectiveInjector . throwOrNull (core.umd.js:3394) 在 ReflectiveInjector getByKeyDefault (core.umd.js:3433) at ReflectiveInjector . getByKeyDefault (core.umd.js:3433) 在 ReflectiveInjector getByKey (core.umd.js:3380) at ReflectiveInjector .get (core.umd.js:3140) at AppModuleInjector.NgModuleInjector.get (core.umd.js:8996) at CompiledTemplate.proxyViewClass.AppView.injectorGet (core.umd.js:12465) at CompiledTemplate.proxyViewClass.DebugAppView.injectorGet (core.umd.js:12845) at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.createInternal (/AppModule/AppComponent/host.ngfactory.js:15) at CompiledTemplate.proxyViewClass.AppView.createHostView (core.umd.js:12421) at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (core.umd.js:12829) at ComponentFactory.create (core.umd.js:7766) 1 : https://github.com/angulartics/angulartics2 getByKey (core.umd.js:3380) at ReflectiveInjector .get (core.umd.js:3140) at AppModuleInjector.NgModuleInjector.get (core.umd.js:8996) at CompiledTemplate.proxyViewClass.AppView.injectorGet (core.umd) .js:12465) at CompiledTemplate.proxyViewClass.DebugAppView.injectorGet (core.umd.js:12845) at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.createInternal (/AppModule/AppComponent/host.ngfactory.js:15) at CompiledTemplate.AppComponent.proxyView .createHostView (core.umd.js:12421) at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (core.umd.js:12829) at ComponentFactory.create (core.umd.js:7766) 1 : https://github.com /angulartics/angulartics2

App.component.ts App.component.ts

import { Component } from '@angular/core';
import { Angulartics2GoogleAnalytics } from 'angulartics2';
@Component({
  selector: 'my-app',
  moduleId: module.id,
  templateUrl: `./app.component.html`,
  styleUrls: ['/app.componenet.css']
})
export class AppComponent {
title = 'Angular2 google analytics';
constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {}
}

app.module.ts app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';
import { HttpModule } from '@angular/http';
import { FormsModule }   from '@angular/forms';
import { Angulartics2Module, Angulartics2GoogleAnalytics } from 'angulartics2';
@NgModule({
  imports:      [ HttpModule, BrowserModule, FormsModule, Angulartics2Module.forRoot([ Angulartics2GoogleAnalytics ])],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
})
export class AppModule { }

use providers to initiate your providers in component.使用providers程序在组件中启动您的提供程序。

 @Component({
    selector: 'yourselector',
    styleUrls: [''],
    templateUrl: '',
    providers: [Angulartics2GoogleAnalytics]
})

Try this.尝试这个。

Your problem should reside in your constructor:您的问题应该存在于您的构造函数中:

constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {}

you should add eg public in front of your provider:你应该在你的提供者前面添加例如public

constructor(public angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular2 - 没有ExceptionHandler的提供者 - Angular2 - No provider for ExceptionHandler Angular2 - 没有LoggedInGuard的提供者 - Angular2 - No provider for LoggedInGuard Angular2更新为rc5和@ angular / router-原始例外:没有路由器的提供程序 - Angular2 updated to rc5 and @angular/router - ORIGINAL EXCEPTION: No provider for Router Angular2:在 Angular2 中使用 Jquery:错误:没有 Token jQuery 的提供者 - Angular2 : Using Jquery in Angular2 : Error: No provider for Token jQuery Angular2 测试用例显示 NgControl 没有提供者 - Angular2 testcase shows No provider for NgControl Angular2:提供模型服务-“没有模型提供者” - Angular2: Service with Model - “no provider for model” Electron app中的Angular2错误:没有PlatformRef的提供者 - Angular2 error in Electron app: No Provider for PlatformRef Angular2-无效的NgModule提供程序,仅允许提供程序和类型的实例 - Angular2 - Invalid provider for the NgModule only instances of Provider and Type are allowed 添加提供程序@NgModule时,Angular2“没有服务提供程序!”错误 - Angular2 “No provider for Service!” error when provider is added @NgModule Angular2-例外:TypeError:未定义不是函数 - Angular2 - EXCEPTION: TypeError: undefined is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM