[Angular] Send Data via HTTP using Angular httpparams

Source: Internet
Author: User
Tags export class

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.