加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

错误TS2307:无法为HttpClientModule找到模块’@ angular / comm

发布时间:2020-12-17 06:54:57 所属栏目:安全 来源:网络整理
导读:我正在尝试使用app.module.ts中的以下行导入HttpClientModule: import { HttpClientModule } from ‘@angular/common/http’; 和 imports: [ ... HttpClientModule,...] 但是我一直得到同样的错误: src/app/app.module.ts(4,38): error TS2307: Cannot fin
我正在尝试使用app.module.ts中的以下行导入HttpClientModule:

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

imports: [
    ...
    HttpClientModule,...
]

但是我一直得到同样的错误:

src/app/app.module.ts(4,38): error TS2307: Cannot find module ‘@angular/common/http’.

尽管这些教程中包含了这些确切的行:

> https://angular.io/guide/http
> https://medium.com/codingthesmartway-com-blog/angular-4-3-httpclient-accessing-rest-web-services-with-angular-2305b8fd654b
> http://blog.ninja-squad.com/2017/07/17/http-client-module/

我该如何解决这个问题并使用HttpClient?

解决方法

新的http客户端仅在4.3版本中添加.你可能正在使用较旧的角度版本.您需要更新项目.进入package.json并修改所有@angular / …条目以包含^ 4.3.4版本.

此外,如果您正在使用SystemJS,则需要向地图添加两个条目:

'tslib': 'npm:tslib/tslib.js','@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',

另见Difference between HTTP and HTTPClient in angular 4?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读