Skip to content

Cyclic dependency when injecting AppInsightService in another service #54

@kart33k

Description

@kart33k

Hi,
We are using Angular 6.0.2 with angular CLi 6.0.1

i am trying to log to app insights by using a globalerror handler and loggerservice.
When trying to inject AppInsightservice to Loggerservice getting cyclicDependency error.

But when i put the service in a specific component it works, but i want to log all errors not component specific.

GlobalErrorHandler
`import { LoggerService } from './../services/logger.service';
import { ErrorHandler, Injectable, Injector } from '@angular/core';

@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
constructor(private logger: LoggerService) {
super();
}
handleError(error: any) {
this.logger.log(error);

    super.handleError(error);
};

}`

LoggerService
`import { Injectable } from '@angular/core';
import { AppInsightsService } from '@markpieszak/ng-application-insights';
@Injectable()
export class LoggerService {

constructor(private appInsightsService: AppInsightsService) { }
log(error) {
console.log('Logger', error);
//this.appInsightsService.trackEvent('ShoppingCart Saved', { 'user': 'test', 'cart': 'test1' });
}
}
`

compiler.js:11362 Uncaught Error: Provider parse errors:
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
at NgModuleProviderAnalyzer.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleProviderAnalyzer.parse (compiler.js:11362)
at NgModuleCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.NgModuleCompiler.compile (compiler.js:11731)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModule (compiler.js:22591)
at compiler.js:22550
at Object.then (compiler.js:206)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js:22508)
at CompilerImpl.push../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:143)
at PlatformRef.push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule (core.js:4790)
at Object../src/pos.main.ts (pos.main.ts:11)

Any help is appreciated.
Thanks
K

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions