I'm using angular-cli
with Angular 5. I am trying to create a service that uses another service itself.
However, I keep getting alternating errors of "Can't resolve all parameters for [service name]: (?)." and "Can't resolve all parameters for e: (?, ?, ?, ?)."
Here is my setup:
MyLoggerService
import { Injectable, Inject, forwardRef } from "@angular/core";
import { OtherLoggerService } from "@A/AServices";
// OtherLoggerService is from a package I installed via npm, so I won't include it here.
// I thought I was missing this @Injectable decorator, but adding it to my
//code gives me the e: (?, ?, ?, ?) error
//Without this @Injectable() line, I get the MyLoggerService: (?) error.
@Injectable()
export class DMLoggerService extends {
constructor(
@Inject(forwardRef(() => OtherLoggerService)) private otherLoggerService: OtherLoggerService
) { }
public logEvent(): void {
this.otherLoggerService.logEvent();
}
public trackPageView(): void {
this.otherLoggerService.trackPageView();
}
}
MyComponent
import { Component, Inject, forwardRef} from "@angular/core";
import { OtherLoggerService} from "@A/AServices";
import { MyLoggerService } from "../../common/services/mylogger.service";
import { AnotherService } from "@A/AServices";
@Component({
selector: "my-component",
templateUrl: "./my-component.component.html"
})
export class MyComponent{
constructor(
@Inject(forwardRef(() => MyLoggerService)) private myLoggerService: MyLoggerService,
private anotherService: AnotherService
) {
this.myLoggerService.trackPageView();
this.anotherService.someFunc();
}
}
MyModule
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { CommonModule } from "@angular/common";
import { OtherLoggerService} from "@A/AServices"; // Just added this per comments, but still receive the same errors
import { MyLoggerService } from "../../common/services/mylogger.service";
import { AnotherService } from "@A/AServices";
@NgModule({
imports: [
CommonModule
BrowserModule
],
declarations: [],
providers: [OtherLoggerService, MyLoggerService, AnotherService]
// Added OtherLoggerService to this array but still received errors
})
export class MyModule { }
The problem is something related to the Injectors somewhere, but I'm unsure where to go. I have been moving in circles alternating the same two errors.
I am not using any Barrels, as I understand it, so ideally it shouldn't be an import-ordering problem.
I've seen the similar topics but have yet to find any working solution.
Edit: Both "OtherLoggerService" and "AnotherService" are services brought in from a package I installed with npm, so I won't post their contents here. However, if there is something I can learn from or need to keep in mind as a result of using them, please share your comments.
Edit: Added an import for OtherLoggerService
on MyModule
but still receiving errors.
Edit: Tried adding OtherLoggerService
into the Providers array on MyModule
, still receiving errors.