简体   繁体   中英

Angular replaced @angular/http with @angular/common/http

I am in the process of upgrading my project and need to change my api from @angular/http to @angular/common/http . I main question do I just need to change the import or will the code need to change?

Old Version Code import { Http, Response, URLSearchParams, Headers } from "@angular/http";

getGridPage(gridQueryData: OrderTemplateTool.Core.Models.Grid.GridQueryData): Promise<Response> {
    return this.http.post(this.apiUrls.GetGridPage, JSON.stringify(gridQueryData), { headers: ServiceBase.headers }).toPromise();
}

New import for package has been deprecated

import { HttpClient, Response, URLSearchParams, Headers } from "@angular/common/http";

I recently went through this and found the code I was using worked fine once I updated the import. HttpClient, Response, URLSearchParams, Headers should work the same with the new import.

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