I'm running into an issue with my simple Angular application that I am having trouble debugging. Whenever I try to inject a service into the constructor I get the an error saying Can't resolve all parameters for LoginService (?)
app.component.ts
import { Component, Injector } from '@angular/core'; import { LoginService } from './login.service'; @Component({ selector: 'app-home', template: require('./app.component.html') }) export default class AppComponent { constructor(private loginService: LoginService) {} }
login.service.ts
import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable() export class LoginService { constructor(private http: HttpClient) { } login() { // Do http requests here } }
app.module.ts
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule, HttpClient } from '@angular/common/http'; // Components import AppComponent from './app.component'; //Services import { LoginService } from './login.service'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, HttpClientModule], providers: [LoginService, HttpClient], bootstrap: [AppComponent] }) export default class AppModule {} Seems to be a problem around the injection of the HttpClient but I cant figure out what exactly.
Any ideas what could be wrong here?
HttpClientin yourapp.module.ts, it should only be imported in the service