Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 http get with parameters - difference between search and params

Tags:

angular

In Angular 4's HTTP package ('@angular/http'), a URLSearchParams object can be passed in the get request. When assigning the parameters object in the request method, what is the difference between using search and params as the attribute to pass the value into?

For example, what is the difference between the following two pieces of code:

let params = new URLSearchParams();
params.set('param1', 'xyz');
this.http.get('url', { search: params });

and

let params = new URLSearchParams();
params.set('param1', 'xyz');
this.http.get('url', { params: params });

Many thanks.

like image 891
Dreamlord Avatar asked Jul 14 '17 09:07

Dreamlord


1 Answers

Search is deprecated since 4.0 and params is preferred way of passing query params.

like image 55
inputError Avatar answered Nov 20 '22 20:11

inputError