{"id":2365,"date":"2020-03-04T18:28:16","date_gmt":"2020-03-04T18:28:16","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=2365"},"modified":"2020-03-04T18:30:05","modified_gmt":"2020-03-04T18:30:05","slug":"url-parameter-changes-when-switching-to-httpclient","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=2365","title":{"rendered":"URL Parameter changes when switching to HttpClient"},"content":{"rendered":"<p>From Angular 4.3 onwards, the HttpClient is preferred over the old Http service.<\/p>\n<p>When creating and passing URL parameters, the new HttpParams object must be used.<\/p>\n<p>Details and examples of this are shown <strong><a href=\"https:\/\/stackoverflow.com\/questions\/47551458\/how-to-pass-urlsearchparams-in-the-httpclient-get-method-angular-5\">here<\/a>.<\/strong><\/p>\n<p>Note carefully as per the post that when passing parameters to the http methods e.g. <em>get<\/em>, the json property name is now &#8216;params&#8217; instead of &#8216;search&#8217;, and the <em>append<\/em> method should be called to add parameters (although the last poster indicates that calling <em>set<\/em> worked for him as well).<\/p>\n<p>Another gotcha is that the HttpParams object is also immutable, so that every time you add a parameter a new object is created\/returned and you <strong>must<\/strong> use the returned object, e.g. in fluent style when adding multiple parameters, otherwise you will end up using your empty initial\u00a0HttpParams object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From Angular 4.3 onwards, the HttpClient is preferred over the old Http service. When creating and passing URL parameters, the new HttpParams object must be used. Details and examples of this are shown here. Note carefully as per the post that when passing parameters to the http methods e.g. get, the json property name is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[198,77],"tags":[],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2365"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2365"}],"version-history":[{"count":4,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2365\/revisions"}],"predecessor-version":[{"id":2369,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2365\/revisions\/2369"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}