Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[e]: #20339

Closed
humarkx opened this issue Nov 10, 2017 · 94 comments
Closed

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[e]: #20339

humarkx opened this issue Nov 10, 2017 · 94 comments

Comments

@humarkx
Copy link

humarkx commented Nov 10, 2017

https://image.prntscr.com/image/4Huq_HhQTHyIjYKH0ztgKw.png

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[e]: StaticInjectorError[e]: NullInjectorError: No provider for e!

@humarkx
Copy link
Author

humarkx commented Nov 10, 2017

Importing both HttpModule and HttpClientModule fixes the problem.

import { HttpClientModule } from '@angular/common/http'; import { HttpModule } from '@angular/http';

@vicb
Copy link
Contributor

vicb commented Nov 10, 2017

@ocombe is working on a fix (better error message)

@SK-Agrawal
Copy link

Add import { HttpModule } from '@angular/http'; in app.module.ts

@Heena-Vora
Copy link

still not working for me

@raghavjatin
Copy link

also not working for me , same error

@Moshiour027
Copy link

same here

@ocombe ocombe removed their assignment Dec 18, 2017
@Muhammad-Soban
Copy link

Not working for me

@crowster
Copy link

crowster commented Dec 19, 2017

in app module
Step 1 add import
import { HttpModule } from '@angular/http';
Step 2 add HttModule in :
imports: [
HttpModule
],
.....

Maybe you need to add in the service
import { Http ,HttpModule} from '@angular/http' too

@RyannGalea
Copy link

Have the same issue :(

@danielszuk
Copy link

danielszuk commented Dec 22, 2017

same issue here (ive imported the httpmodule, but still not working)

@jersonjohn
Copy link

Same error , Not working for me too

@mumairofficial
Copy link

Worked by importing HttpClientModule even I am not using this module in whole app.. that's wired.

@jersonjohn
Copy link

Have to add app.module.ts under provider section to make them available in providers

Problem fixed!! HUHU

@ilivestrong
Copy link

@jersonjohn - Which service to registere in Providers section. I am facing the same issue and after reading above suggestions, I have already imported HttpClient and HttpClientModule in my app.module.ts (even though I am not using them)...

Please advise.

Thanks
Deepak

@ilivestrong
Copy link

capture

@jersonjohn
Copy link

providers: [
AuthGuard,
CookieService,
CompanyService,
PolicyService,
CommunicationService,
AuthenticationService
]

@jersonjohn
Copy link

@ilivestrong all services need to configure in the providers section of the app.module.ts

Something like this

providers: [
AuthGuard,
CookieService,
CompanyService,
PolicyService,
CommunicationService,
AuthenticationService
]

@ilivestrong
Copy link

@jersonjohn - I already have all my custom services and angular services in providers array. Not sure why it's not working. I am just trying to build a login page using a reactive form (using FormBuilder).

Not sure what is breaking it...

@mumairofficial
Copy link

@ilivestrong have you included ReactiveFromsModule in import array of app.module.ts

@ilivestrong
Copy link

@mumairofficial - Yes I did. Strangely I created a new project and it went away, only until I wrote a new route guard and I get this StaticInjectionError for my route guard now.

This route guard is provided as well. :(

@HanVertegaal
Copy link

I had the same problem after creating a new service using ng-cli. This should automatically add the service to the providers array in app.module.ts

@VikashChoudahry
Copy link

I had same issue but after importing "HttpModule" in "app.module.ts" it worked fine for me.

  1. import { HttpModule } from '@angular/http';
  2. Add "HttpModule" in imports array list.

Thanks.
Keep Sharing.

@ShahidMirza2017
Copy link

Add import { HttpModule } from '@angular/http'; in app.module.ts for Http
Or
Add import {HttpClientModule} from '@angular/common/http' in app.module.ts for httpclient

@amitkprajapati
Copy link

I imported both HttpModule and HttpClientModule but still getting the same error , Please any one help me out , i am trying to implement routing .

@nvigneux
Copy link

nvigneux commented Jan 2, 2018

@amitkprajapati import HttpClientModule in app.module.ts

import { HttpClientModule } from '@angular/common/http'
///
@NgModule({
  imports: [ HttpClientModule ]
})

@MehdiZohrevnd
Copy link

however someone answered correctly but i refer to correct solution too ....
1 - if you'r version is '6' in app.module use 'HttpClientModule' and 'HttpClient' from '@angular/common/http':

2 - otherwise use 'HttpModule' and 'Http' from '@angular/http':

@asrar7
Copy link

asrar7 commented May 17, 2018

@MehdiZohrevnd what should be version 6 ?

@bfheythem
Copy link

I am having the same issue , even when I do the HttpClientModule imports :/ plz help

@panchomr
Copy link

Hi , i solved this way , in angular 6 httpModule is deprecated and was removed from Angular.

this is my app.module.ts

import { HttpClientModule } from '@angular/common/http';

and then add into imports:

imports: [
    APP_ROUTING,
    BrowserModule,
    RouterModule,
    HttpClientModule
  ],

in my service

import { HttpClient, HttpHeaders, HttpClientModule } from '@angular/common/http';

and this works for me

cheers!

@itamark
Copy link
Contributor

itamark commented Jun 22, 2018

As was mentioned above, this worked for me:
In app.module.ts import HttpClientModule and include it in your imports array.
In your service use HttpClient (http: HttpClient in constructor)

@omsaravanan
Copy link

Using Angular 6 and tried every suggestion... the problem continues... pls suggest

@adrobson
Copy link

adrobson commented Aug 1, 2018

In my case I had multiple resolvers and was using the wrong syntax by putting a [] around the resolvers eg [{name1:resolver1{,{name2:resolver2}] . Instead the syntax should be {name1:resolver1,name2:resolver2}

@SK-Agrawal
Copy link

SK-Agrawal commented Aug 1, 2018 via email

@jardelsimao
Copy link

this worked for me

@Injectable({
providedIn: 'root',
})

@alundiak
Copy link

alundiak commented Aug 5, 2018

Just in case someone needs additional info, especially if it's about erros with ng test.
I had this error(s):

Error: StaticInjectorError(DynamicTestModule)[HttpClient]:
StaticInjectorError(Platform: core)[HttpClient]:
NullInjectorError: No provider for HttpClient!

So this is what helped me:

I added to my xyz.component.spec.ts file

import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';

and

TestBed.configureTestingModule({
      imports: [ HttpClientModule, ReactiveFormsModule, RouterTestingModule ], // new line
      declarations: [ BookCreateComponent ],
      schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})

In fact,

  • Injection of HttpClientModule helps to get rid of StaticInjectorError
  • Injection of ReactiveFormsModule helps to get rid of Can't bind to 'formGroup' since it isn't a known property of 'form' errors.
  • Injection of RouterTestingModule helps to get rid of Can't bind to 'routerLink' since it isn't a known property of 'a'.

Notes:

  • Angular v6.0.0, Angular Material v 6.0.2, Angular CLI v6.0.0.
  • but also verified with Angular v6.1.1 and Angular CLI v6.1.2.
  • Node v10.8.0, npm v6.2.0, MacOS, Chrome v68.0.

@mhswork
Copy link

mhswork commented Aug 7, 2018

One of the ways I was able to solve this issue is:

Add "HttpClientModule" existing in '@angular/common/http' inside app.module.ts file and add "HttpCleint" existing in '@angular/common/http' inside the component/service typescript file wherein you are sending Http requests.

@Con607
Copy link

Con607 commented Aug 16, 2018

In the auth.guard.ts

@Injectable({
    providedIn: 'root',
})

@christiantigre
Copy link

I solved
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';

imports: [
BrowserModule,
HttpModule,
HttpClientModule,
IonicModule.forRoot(MyApp)
],

for mi

@noameini
Copy link

noameini commented Sep 3, 2018

Problem fixed !
Thank you all !

@Jasa-Bcone
Copy link

Importing both HttpModule and HttpClientModule fixes the problem.

import { HttpClientModule } from '@angular/common/http'; import { HttpModule } from '@angular/http';

if we are using {Http ,Headers, or anything } from '@angular/http'; in app.compontent.ts file or app.service.ts file or any otherfile.ts then we have to add HttpModule in app.module.ts before using these in service.ts file or component.ts file

@macyun
Copy link

macyun commented Jan 7, 2019

image
image
image

not working for me..

@macyun
Copy link

macyun commented Jan 8, 2019

angular-cli version is too high, Problem fixed

@akrun143
Copy link

akrun143 commented Jan 8, 2019

angular-cli version is too high, Problem fixed

how did you fix it

@macyun
Copy link

macyun commented Jan 9, 2019

angular-cli version is too high, Problem fixed

how did you fix it

Reduce the @angular/cli version to 6.2.8

@MarcioBdeveloper
Copy link

the correct amount is { Http } from '@angular/http'; in Providers

@Elite40
Copy link

Elite40 commented Jan 20, 2019

I'm using ionic version 3 and the following solution worked for me:

Inside app_module.ts add: import { HttpClientModule } from '@angular/common/http';

Then add that to your imports array, like so:
imports: [ BrowserModule, IonicModule.forRoot(MyApp), HttpClientModule ],

Thanks to #20339 (comment)

@DaveOdden
Copy link

DaveOdden commented Jan 31, 2019

I ended up importing HttpClientModule and the auth-guard file into app.module.ts, supplied the auth guard dependency in the providers array, and the HttpClientModule into the imports array.

import { HttpClientModule } from '@angular/common/http';
import { AuthGuardService } from './app.auth-guard.service';

[...]

@NgModule({
  declarations: [...],
  imports: [ HttpClientModule, ... ],
  providers: [ AuthGuardService, AuthService, {
    provide: AuthServiceConfig,
    useFactory: getAuthServiceConfigs,
  }],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  bootstrap: [AppComponent]
})

note: I did not need to downgrade @angular/cli

@diegodelfin7
Copy link

Thanks . I had same issue but it got fixed

@ghulamakbar14
Copy link

I have same issue but it is not fixed.
My files are:

app.module.ts
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';

imports: [
...
HttpClientModule,
HttpModule
]

package.json

"devDependencies": {
"@angular-devkit/architect": "~0.12.3",
"@angular-devkit/build-angular": "~0.12.3",
"@angular-devkit/core": "~7.2.3",
"@angular-devkit/schematics": "~7.2.3",
"@angular/cli": "7.2.4",
"@angular/compiler": "~7.2.2",
"@angular/compiler-cli": "^7.2.6",
"@angular/language-service": "~7.2.2",
"@ionic/angular-toolkit": "~1.4.0",
"@ionic/lab": "1.0.21",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~10.12.0",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.0.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~8.0.0",
"tslint": "~5.12.0",
"typescript": "~3.1.6"
},

@josemorenoaguilera
Copy link

This work for me:
at the app.module.ts
import { HttpModule } from '@angular/http';

in @NgModule import HttpModule and works!

@oscarhandsome
Copy link

For me helped:
import {HttpClientModule} from '@angular/common/http';
to imports - HttpClientModule
in the app.module.ts

@johnedvard
Copy link

Remember that Pipes also needs to be in the providers' array. I got the error when I had my Pipes in a shared module, exporting them, but forgot to add them as providers.
providers: [MyPipe]

@vijayamurugan
Copy link

The solution is simple that you might be missing services under providers array. When you run in devlopment mode you will be able exactly identify the missing service under providers array. When you run in production mode the error log doesn't show the exact missing service/s under providers.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests