在我的组件中,我导入了以下内容
import { Http, Response, URLSearchParams, HttpClient, HttpHeaders } from '@angular/common/http';但我知道这个错误
ERROR in src/app/app.module.ts(35,9): error TS2305: Module '"/Users/strypeez/Dropbox/gosco-webNEW/gosco-webUPTODATE/node_modules/@angular/common/http"' has no exported member 'HttpModule'.
src/app/ownership-cost/ownership-form.component.ts(8,10): error TS2305: Module '"/Users/strypeez/Dropbox/gosco-webNEW/gosco-webUPTODATE/node_modules/@angular/common/http"' has no exported member 'Http'.
src/app/ownership-cost/ownership-form.component.ts(8,16): error TS2305: Module '"/Users/strypeez/Dropbox/gosco-webNEW/gosco-webUPTODATE/node_modules/@angular/common/http"' has no exported member 'Response'.
src/app/ownership-cost/ownership-form.component.ts(8,26): error TS2305: Module '"/Users/strypeez/Dropbox/gosco-webNEW/gosco-webUPTODATE/node_modules/@angular/common/http"' has no exported member 'URLSearchParams'. 当我使用“@转角/http”时,我并没有得到错误;但是弃用注释说要将它更改为“@转角/公共/http”;是什么导致了错误?
发布于 2018-04-19 13:56:52
您应该从HttpClientModule中使用@angular/common/http,并使用下面的语句
import { HttpClientModule } from '@angular/common/http'原因:HttpModule在@angular/http包中可用,不推荐使用
更新1:基于stackblitz
您的导入语句是错误的,因为只有少数模块级别的更改是由角度和文档化的,修改后的导入语句看起来应该如下所示
import { HttpClientModule, HttpHeaders } from '@angular/common/http';
import { Http, Response, URLSearchParams } from '@angular/http';发布于 2018-04-19 13:58:05
您是否在您的主模块中导入:
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})https://stackoverflow.com/questions/49922942
复制相似问题