admin管理员组

文章数量:1406060

I want to import HttpHeaders but when I import it I get this error :

Uncaught Error: Unexpected value 'HttpHeaders' imported by the module 'AppModule'. Please add a @NgModule annotation.

I import this :

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

into my app.module.ts and into my service.ts

and I import this :

@NgModule({
  declarations: [
    AppComponent,
    PremierComComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    HttpClientModule,
    HttpHeaders,

  ],
  providers: [],
  bootstrap: [AppComponent]
})

in the app.module.ts

Can someone explain me how to solve the error?

I want to import HttpHeaders but when I import it I get this error :

Uncaught Error: Unexpected value 'HttpHeaders' imported by the module 'AppModule'. Please add a @NgModule annotation.

I import this :

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

into my app.module.ts and into my service.ts

and I import this :

@NgModule({
  declarations: [
    AppComponent,
    PremierComComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    HttpClientModule,
    HttpHeaders,

  ],
  providers: [],
  bootstrap: [AppComponent]
})

in the app.module.ts

Can someone explain me how to solve the error?

Share Improve this question edited Nov 4, 2018 at 1:03 bcperth 2,3011 gold badge14 silver badges20 bronze badges asked Nov 3, 2018 at 21:16 Dany AssuidDany Assuid 111 gold badge1 silver badge2 bronze badges 2
  • 6 The imports array is for importing modules, such as the HttpClientModule above. It can only contain modules, but HttpHeaders is not a module – user184994 Commented Nov 3, 2018 at 21:18
  • 1 HttpHeaders should be imported just in the service that use it. Inject Http and add, in the function, the custom headers. – Jacopo Sciampi Commented Nov 3, 2018 at 21:19
Add a ment  | 

1 Answer 1

Reset to default 3

The HttpHeaders are a class. The only thing which should be in your imports is an array of modules which are always decorated with the @NgModule tag. So you should remove the HttpHeaders from the imports array.

Sources:

  • Angular HttpHeaders
  • Angular Http

本文标签: javascriptangular 6 Please add a NgModule annotationStack Overflow