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 theHttpClientModule
above. It can only contain modules, butHttpHeaders
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
1 Answer
Reset to default 3The 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
版权声明:本文标题:javascript - angular 6 Please add a @NgModule annotation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744959446a2634562.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论