HttpParameterCodec : is a codec for encoding and decoding parameters in URLs( Used by HttpParams).

If you need to encode Url you can use the below:

encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it.

encodeURIComponent will encode everything with special meaning, so you use it for components of URIs, such as:

var textSample= "A sentence with symbols & characters that have special meaning?";
var uri = 'http://example.com/foo?hello=' + encodeURIComponent(textSample);
Answer from nircraft on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › how-can-i-invoke-encodeuricomponent-from-angularjs-template-in-html
How can I invoke encodeURIComponent from AngularJS template in HTML?
December 15, 2022 - In the following example we are using the function encodeURIcomponent(string) to encode the url parameters. <!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("mytutorials", []); ...
🌐
GeeksforGeeks
geeksforgeeks.org › angularjs › how-to-encode-decode-url-using-angularjs
How to encode/decode URL using AngularJS ? - GeeksforGeeks
July 24, 2025 - Example 1: This example describes the encoding of URL using the encodeURIComponent() method. ... <!DOCTYPE HTML> <html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = ...
🌐
Stack Overflow
stackoverflow.com › questions › 34674816 › angular-routeprovider-and-encodeuricomponent
Angular routeProvider and encodeURIComponent
That works fine but when I click on the encoded link a) the firefox browser shows the link without the encoding b) the angular routeProvider does not recognize the URL and does it's default routing. ... $scope.cellTemplate = function(url) { var s = '<div class="{{' + isRowInactive() + ' ? \'ui-grid-cell-contents strikethru\' : \'ui-grid-cell-contents\'}}" ng-class="col.colIndex()">' + '<span >'; if (url) s += '<a ng-href="#/client/{{ row.entity.id | encodeURIComponent }}">'; s += '{{ grid.getCellValue(row, col) }}'; if (url) s += '</a>'; s += '</span></div>'; return s; };
🌐
GitHub
github.com › angular › angular › issues › 24754
HTTP GET Query string encoding · Issue #24754 · angular/angular
July 4, 2018 - Please describe: The HttpClient.get() ... Here's an example : constructor( private http: HttpClient, ) { } httpRequest() { this.http.get('example.com', { params: { encoded: encodeURIComponent('i\'m URI ......
Author   angular
🌐
GitHub
github.com › swagger-api › swagger-codegen › issues › 6524
[typescript-angular2]: use encodeURIComponent for path parameters · Issue #6524 · swagger-api/swagger-codegen
September 20, 2017 - ... const path = this.basePath + '{{{path}}}'{{#pathParams}} .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; ... const path = this.basePath + '{{{path}}}'{{#pathParams}} .replace('${' + '{{baseName}}' + '}', ...
Author   swagger-api
🌐
Better Programming
betterprogramming.pub › how-to-fix-angular-httpclient-not-escaping-url-parameters-ddce3f9b8746
How To Fix Angular HttpClient Not Escaping URL Parameters | by Ali Kamalizade | Better Programming
March 28, 2023 - Use the custom encoder class when creating new HttpParams: new HttpParams({ encoder: new CustomHttpParamEncoder() }). The important part is the usage of encodeURIComponent, which is a vanilla JavaScript function to encode a string.
🌐
TutorialsPoint
tutorialspoint.com › how-to-encode-and-decode-url-in-typescript
How to encode and decode URl in typescript?
January 16, 2023 - This example demonstrates the use of the encodeURIComponent() method to encode the part of the URL. We have taken the URL string containing the special characters. After that, we used the encodeURIComponent() method to encode the ?index.php<>? ...
Find elsewhere
🌐
StackBlitz
stackblitz.com › edit › angular-url-encode
Angular Url Encode - StackBlitz
Starter project for Angular apps that exports to the Angular CLI
🌐
Angular
v17.angular.io › api › common › http › HttpUrlEncodingCodec
Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.
🌐
W3Schools
w3schools.com › jsref › jsref_encodeuricomponent.asp
JavaScript encodeURIComponent() Method
The encodeURIComponent() method encodes special characters including: , / ?
🌐
GitHub
github.com › fknop › angular-pipes › blob › master › src › string › encode-uri-component.pipe.ts
angular-pipes/src/string/encode-uri-component.pipe.ts at master · fknop/angular-pipes
February 23, 2023 - import { Pipe, PipeTransform, NgModule } from '@angular/core'; import { isString } from '../utils/utils'; · @Pipe({ name: 'encodeURIComponent', }) export class EncodeURIComponentPipe implements PipeTransform { transform(input: any) { if (!isString(input)) { return input; } ·
Author   fknop
🌐
GitHub
github.com › angular › angular › issues › 33728
HttpUrlEncodingCodec reverses part of the encoding · Issue #33728 · angular/angular
November 11, 2019 - See code (https://github.com/angular/angular/blob/8.2.13/packages/common/http/src/params.ts#L81-L92): function standardEncoding(v: string): string { return encodeURIComponent(v) .replace(/@/gi, '@') .replace(/:/gi, ':') .replace(/$/gi, '$') .replace(/,/gi, ',') .replace(/;/gi, ';') .replace(/+/gi, '+') .replace(/=/gi, '=') .replace(/?/gi, '?') .replace(///gi, '/'); }
Author   angular
Top answer
1 of 3
4

Angular (at least 1.3) doesn't only use encodeURIComponent and changes some replacements (like " " to "+").

this is the commit explaining why : https://github.com/angular/angular.js/commit/9e30baad3feafc82fb2f2011fd3f21909f4ba29e

And here's what you can see in 1.3 sources :

/**
 * This method is intended for encoding *key* or *value* parts of query component. We need a custom
 * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
 * encoded per http://tools.ietf.org/html/rfc3986:
 *    query       = *( pchar / "/" / "?" )
 *    pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
 *    unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
 *    pct-encoded   = "%" HEXDIG HEXDIG
 *    sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
 *                     / "*" / "+" / "," / ";" / "="
 */
function encodeUriQuery(val, pctEncodeSpaces) {
  return encodeURIComponent(val).
             replace(/%40/gi, '@').
             replace(/%3A/gi, ':').
             replace(/%24/g, '$').
             replace(/%2C/gi, ',').
             replace(/%3B/gi, ';').
             replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}

note that pctEncodeSpaces is hardcoded to true;

Here's what you can do to decode URI parameters

decodeURIComponent(val.
             replace('@', '%40').
             replace(':', '%3A').
             replace('$', '%24').
             replace(',', '%2C').
             replace(';', '%3B').
             replace('+', '%20'));
2 of 3
4

In my humble opinion AngularJS is wrongly encoding in the same way URI path segments AND URI query parameters. To me this is a bug and I actually issued a pull request for fixing it.

The test I introduce in the pull request actually confirms this bug (tested it with both AngularJS 1.3.* and current master).

  • https://github.com/angular/angular.js/pull/12201
🌐
GitHub
github.com › angular › angular › issues › 30379
URL query string value encoding · Issue #30379 · angular/angular
May 10, 2019 - function standardEncoding(v: string): string { return encodeURIComponent(v) .replace(/@/gi, '@') .replace(/:/gi, ':') .replace(/$/gi, '$') .replace(/,/gi, ',') .replace(/;/gi, ';') .replace(/+/gi, '+') .replace(/=/gi, '=') .replace(/?/gi, '?') ...
Author   angular
🌐
GitHub
github.com › angular › angular.js › issues › 8064
$http should use encodeURIComponent for encoding query string parameters · Issue #8064 · angular/angular.js
July 3, 2014 - I was expecting AngularJS to encode query string parameters using encodeURIComponent. According to the following test it is not the case: describe('$http', function () { it('encodes uri components correctly', inject(function($http, $httpBackend) { var data = 'Hello from http://example.com'; $httpBackend.expectGET('/api/process?data=' + encodeURIComponent(data)); $http({ method: 'GET', url: '/api/process', params: { data: data } }); $httpBackend.flush(); })); }); The test fails with the following error: $http encodes uri components correctly Error: Unexpected request: GET /api/process?data=Hello+from+http://example.com Expected GET /api/process?data=Hello from http://example.com ·
Author   angular
🌐
Stack Overflow
stackoverflow.com › questions › 39893975 › http-get-pass-encodeuricomponent-to-web-api
angularjs - $http.get pass encodeURIComponent to Web API - Stack Overflow
find: function (id) { var scope = this; var urlApi = webapi_base_url + model_url; id = encodeURIComponent(id); return $http.get(urlApi + id) .then(function (response) { if (response.data.success && response.data.exists) { //logger.info('Successfully found model', '', 'Success'); } else { if (showLogger) logger.error(response.data.error, '', 'Error'); } return response.data; }) .catch(function (err) { scope.WebFailed('get', err); }) } For example I want to pass the values a+ to my web api, the url is: