Summary: Starting with the angular 4.3.0 version of the HttpClient, replacing the previous HTTP, the referenced package path has been changed to Angular/common/http
A basic example of a httpclient sample
Import {injectable}From' @angular/core ';Import {HttpClient, HttpResponse}From' @angular/common/http ';Import {Observable}From' Rxjs/observable ';Import {httpdefaultoptions}From'./http.default.options ';@Injectable ()ExportClass Service {PrivateStatic Method_delte =' DELETE ';PrivateStatic Method_post =' POST ';PrivateStatic Method_get =' GET ';PrivateStatic Method_put =' PUT ';ConstructorPrivatehttpclient:httpclient) {}/** * Upload Data *@param data *@param {Function} func */Uploaddatapost (Data:any,FuncFunction) {Let URL ='/api/test ';This.apipost (URL, data). Subscribe (Response:httpresponse) = {func (response);}, Error = = {Func (undefined); }); }/** * Returns the Obj object in JSON format *@param URL *@param body *@param urlsearchparams *@returns {observable<{}>} */Apipost (URL, body, urlsearchparams?: any): observable<{}> {Let options = {Body:body? Body:null, params:urlsearchparams, responsetype: ' json '}; return this.httpClient.request (service.method_post, URL, options);} /** * Returns an obj object * @param URL * @param query parameters for urlsearchparams URL * @returns {observable<{}>} */Apig ET (URL, urlsearchparams): observable<{}> {let options = { Params:urlsearchparams, responsety PE: ' json '}; return this.httpClient.request (service.method_get, URL, options);}}
Angular5 httpclient Examples of actual combat