4

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?

3
  • Migh be the path of impott is wrong or may be misspelled lIke in actual capital L is there but you spelled it small l Commented Jun 27, 2018 at 16:03
  • I'm pretty sure you don't need HttpClient in your app.module.ts, it should only be imported in the service Commented Jun 27, 2018 at 16:10
  • 2
    @Und3rTow, you're right thanks, removing, I was getting desperate! Commented Jun 27, 2018 at 16:11

2 Answers 2

2

Turned out to be a missing import!

import 'core-js/es7/reflect'; 
Sign up to request clarification or add additional context in comments.

1 Comment

glad i stumbled across this when i upgraded from angular 6 to 7, i kept getting can not resolve all parameters for HttpXSRFInterceptor... even though i wasn't even using that interceptor... adding this to polyfills.ts fixed issue
0

This can also happen if you've upgraded to Angular 9+ but have disabled Ivy and you're using a library that was compiled with ngc with Ivy turned on. The solution is to upgrade to Ivy or to ask the library owner to produce a non-Ivy build as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.