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

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

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 36
  • Comments: 94 (2 by maintainers)

Most upvoted comments

Importing both HttpModule and HttpClientModule fixes the problem.

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

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

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

still not working for me

@amitkprajapati import HttpClientModule in app.module.ts

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

also not working for me , same error

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

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

Problem fixed!! HUHU

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

@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 ]

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

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.

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

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

Not working with any of the solutions.

FILES ----- error system appmodulets homets packagejson

I solve this by following two steps:

import { BrowserModule } from ‘@angular/platform-browser’; … imports: [ BrowserModule, ]

import { HttpModule } from ‘@angular/http’; and then add HttpModule to imports

,imports: [ HttpModule, BrowserModule, IonicModule.forRoot(MyApp), ], This fixes the problem for me. you can also import import { HttpClientModule } from ‘@angular/common/http’; for convenience sake

I had the same problem when I moved a property to a component inside constructor() parameters. It was solved when I moved it out back.

You need provide your dataservices import … import { DataService } from ‘…/dataservice’;

@Component({ selector: '… templateUrl: … styleUrls:…, providers: [DataService] })

angular-cli version is too high, Problem fixed

this worked for me

@Injectable({ providedIn: ‘root’, })

i solved this problem. at ‘app.module.ts’ add

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

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

@ilivestrong I got the same. Adding providers: [UserService] in my userListComponent fixed it.

@Component({
  selector: 'app-user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.css'],
  providers: [UserService]
})

This component is imported by my user-module which itself is imported in app-module.

Hope it helps !

add FreezerService into providers array of app.module.ts

same here

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

In the auth.guard.ts

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

Apart from above solutions… I think removing the NavCtrl from service also helps. Seems there is conflict between NavCtrl of Component and Service/Provider

Stop ionic and rerun “ionic serve” to show real error message to you.

Not working for me

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

image image image

not working for me…

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

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

for mi

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)

Just verify Your Code with below one:

import { BrowserModule } from ‘@angular/platform-browser’; import { NgModule } from ‘@angular/core’; import { HttpClientModule } from “@angular/common/http”;

@NgModule({

declarations: [ … ], imports: [ BrowserModule, HttpClientModule ], providers: [ … ], bootstrap: [AppComponent] })

the above Code resolve the issue

This error was caused by introducing angular2-cookie for me. It works during “ng serve”, but not “ng build --prod”. Solution was simply removing it from the project. Didn’t really use it anyways.

That is because we have not injected our services in app module.

We have to pass our service at 2 places in app.module.ts importing the service added them in providers

import {ConfigService} from ‘./providers/config.service’;

… providers: [ConfigService], …

I also got this working by importing HttpModule from angular/http@5.2.9 in app.module.ts

import { HttpModule } from '@angular/http';
@NgModule({
    imports: [
       ...,
       HttpModule,
       ...
})

I got this error in Angular 5.2.7 and importing HttpClientModule to the app.module.ts solved the the problem, don’t forget to add HttpClientModule to the imports: [] and don’t forget the service provider too providers: []

Just for information ~HttpModule~ is deprecated in favor of HttpClientModule from @angular/common/http package; use the latest one to make upgrade easy 👍

The above one is right .you should define the it in provider of app.module file .

On 19-Jan-2018 1:49 PM, “Jerson” notifications@github.com wrote:

Sorry I am not accessing computers as travelling now

On Fri, Jan 19, 2018 at 4:13 PM, Muhammad Umair notifications@github.com wrote:

@kverma17 https://github.com/kverma17 add Camera to provider array in side of app.module.ts and donot forget to import it 😃

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/angular/angular/issues/20339#issuecomment-358895567 , or mute the thread <https://github.com/notifications/unsubscribe-auth/ ALjmrWMbECJKExNU3ohhoDk0OjiBPymLks5tME6ygaJpZM4QZw3x> .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular/issues/20339#issuecomment-358896806, or mute the thread https://github.com/notifications/unsubscribe-auth/AWbXx5egA7PdAAz_D-twVRcGtjKxLYTYks5tMFAdgaJpZM4QZw3x .

@kverma17 add Camera to provider array in side of app.module.ts and donot forget to import it 😃

I am not sure camera will work properly in browser but the error you have posted will go away.