Upon compiling my application, an error is appearing in the console:
Uncaught Error: Can't resolve all parameters for UserService (?)
Despite having @Injectable()
present for the UserService
, I am unsure where to troubleshoot further.
import {Injectable} from '@angular/core';
import {Observable} from "rxjs";
import {UserModel} from "../../model/user.model";
import {environment} from "../../../environments/environment";
import {HttpClient} from "@angular/common/http";
@Injectable()
export class UserService {
constructor(
private _http: HttpClient
) {
}
getMe(): Observable<UserModel> {
return this._http.get<UserModel>(environment.adminApiUrl + '/me');
}
}
The necessary modules should be included in the app.module.ts
:
import {BrowserModule} from '@angular/platform-browser';
import {Injector, NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {AppRouting} from "./app.routing";
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {LoggerModule, NgxLoggerLevel} from "ngx-logger";
import {environment} from "../environments/environment";
import {AuthGuard} from "./service/guard/auth.guard";
import {UserService} from "./api/service/user.service";
import {CommonModule} from "@angular/common";
import {setAppInjector} from "./app-injector";
import {HttpClientModule} from "@angular/common/http";
const ApiServices = [
UserService
];
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonModule,
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
AppRouting,
// Logging
LoggerModule.forRoot({
serverLoggingUrl: '/',
level: environment.production ? NgxLoggerLevel.OFF : NgxLoggerLevel.TRACE,
serverLogLevel: NgxLoggerLevel.OFF
}),
],
providers: [
AuthGuard,
ApiServices
],
bootstrap: [AppComponent]
})
export class AppModule {
}
Despite these configurations, the error persists.
What could be causing this issue?
If I remove private _http: HttpClient
from the constructor within UserService
, the application functions normally. It seems like the @Injectable()
annotation may not be functioning correctly in my current setup.