简体   繁体   中英

Cannot find module '@angular/http' Angular 9

I am facing an error all of a sudden in a perfectly fine running application

Cannot find module '@angular/http'

import { Http } from '@angular/http'

I am using http to read a json file

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

Please help

angular replaced the http module back in around angular 5 or 6. It's been deprecated for some time. You now need to use the HttpClient and HttpClientModule from @angular/common/http

but be aware that the Http service and the HttpClient service have some important differences that may break your app if it was using Http

Http was deprecated. Use HttpClient

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

@angular/http is depricated and in recent versions and is now removed from the generated package.json file, use HttpClient from '@angular/common/http'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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