繁体   English   中英

找不到模块'@angular/http' Angular 9

[英]Cannot find module '@angular/http' Angular 9

我在一个运行良好的应用程序中突然遇到错误

找不到模块“@angular/http”

import { Http } from '@angular/http'

我正在使用 http 读取 json 文件

 this.http.get('assets/env/env.json').pipe(map( res => res.json()))

请帮忙

angular 在 angular 5 或 6 左右替换了 http 模块。它已被弃用一段时间。 您现在需要使用来自@angular/common/httpHttpClientHttpClientModule

但请注意Http服务和HttpClient服务有一些重要的差异,如果它使用Http可能会破坏您的应用程序

Http已弃用。 使用HttpClient

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

@angular/http已被弃用,在最近的版本中,现在已从生成的package.json文件中删除,请使用来自“@angular/common/http”的 HttpClient。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM