Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[HomeComponent -> HttpHeaders]

Tags:

angular

While fetching from API call using GET method I am facing problem like this

core.js:6014 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[HomeComponent -> HttpHeaders]: StaticInjectorError(Platform: core)[HomeComponent -> HttpHeaders]: NullInjectorError: No provider for HttpHeaders! NullInjectorError: StaticInjectorError(AppModule)[HomeComponent -> HttpHeaders]: StaticInjectorError(Platform: core)[HomeComponent -> HttpHeaders]: NullInjectorError: No provider for HttpHeaders! at NullInjector.get (core.js:855) at resolveToken (core.js:17513) at tryResolveToken (core.js:17439) at StaticInjector.get (core.js:17265) at resolveToken (core.js:17513) at tryResolveToken (core.js:17439) at StaticInjector.get (core.js:17265) at resolveNgModuleDep (core.js:30392) at NgModuleRef_.get (core.js:31577) at resolveDep (core.js:32142) at resolvePromise (zone-evergreen.js:797) at resolvePromise (zone-evergreen.js:754) at zone-evergreen.js:858 at ZoneDelegate.invokeTask (zone-evergreen.js:391) at Object.onInvokeTask (core.js:39679) at ZoneDelegate.invokeTask (zone-evergreen.js:390) at Zone.runTask (zone-evergreen.js:168) at drainMicroTaskQueue (zone-evergreen.js:559)

Code:

return this.http
      .get('http://localhost/advanced/frontend/web/leftside-menu/get-left-menu')
      .subscribe(
        (result) => { }
      );
like image 269
Sai Ram Akuri Avatar asked Nov 07 '19 09:11

Sai Ram Akuri


People also ask

Why am I getting nullinjectorerror error 4?

4 Error: NullInjectorError: No provider for UserModel! 6 etc.. etc.. The error looked like this: The underlying cause of this error is that Angular 5 changed how they create providers moving from a reflect based injector to a static injector. This removes the need for the reflect polyfill that is used in Angular applications.

What is this error 4 error in angular?

4 Error: NullInjectorError: No provider for UserModel! 6 etc.. etc.. The error looked like this: The underlying cause of this error is that Angular 5 changed how they create providers moving from a reflect based injector to a static injector.

How many $injector errors on angular upgrade?

14 routing navigate method not redirecting to targeted component 10 $Injector Error on Angular Upgrade from 1.6.6 to 6 1 NullInjectorError: StaticInjectorError(AppModule)[TranslateService -> TranslateStore] 2

Why is my dependency injection not working in angular 9?

Be careful platform is available only since Angular 9 ( https://blog.angular.io/version-9-of-angular-now-available-project-ivy-has-arrived-23c97b63cfa3) It also might be that you haven't declared you Dependency Injected service, as a provider in the component that you injected it to.


1 Answers

Have you imported HttpClientModule in app.module.ts? if not then put this line code..

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

@NgModule({  
            imports: [ BrowserModule, FormsModule, HttpClientModule ],
            declarations: [ ]
           })
like image 190
GaurangDhorda Avatar answered Nov 01 '22 19:11

GaurangDhorda