Obviously in a real world application we don't only fetch data from the backend, but we also send data to be stored perma nently on the server side. The HttpClient
gives us different options for achieving this. In this lesson we'll look at what attach parameters to our request URL by manually concatenating the URL by ourselves , by using the HttpParams
object and also how we can send entire objects in a POST
request body.
Import {injectable} from ' @angular/core '; import {Observable} from' Rxjs/observable 'Import {HttpClient, httperrorresponse, httpparams } from' @angular/common/http '; Export interface person {name:string;} @Injectable () Export class Peopleservice {constructor (private http:httpclient) {} fetchpeople (): Observable<Person> { //The same As/api/v1/people?id=2&includename=falseCONST PARAMS =NewHttpparams (). Set (' id ', ' 2 '). Set (' Includename ', ' false '); return This. http. Get<Person> ('/api/v1/people ', {params}); }}
[Angular] Send Data via HTTP using Angular httpparams