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
🌐
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; };
🌐
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", []); myApp.controller("mytutorials1", function($scope) { $scope.url1 = 'https://www.tutorialspoint.com/index.htm'; $scope.url2 = ''; $scope.encodeUrlStr = function() { $scope.url2 = encodeURIComponent($scope.url1); } }); </script> </head> <body> <div ng-app="mytutorials"> <div ng-controller="mytutorials1"> <button ng-click ="encodeUrlStr()" >Encode URL</button> <br> URL1 = {{url1}}<br> URL2 = {{url2}} </div> </div> </body> </html>
🌐
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 = angular.module("app", []); myApp.controller("controller", function($scope) { $scope.url1 = "https://www.geeksforgeeks.org//community/"; $scope.url2 = ''; $scope.encodeUrl = function() { $scope.url2 = encodeURIComponent($scope.url1); } }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to encode URL in AngularJS </h3> <div ng-app="app"> <div ng-controller="controller"> URL = '{{url1}}' <br><br> <button ng-click="encodeUrl()"> Click here </button> <br><br> Encoded URL = '{{url2}}' </div> </div> </body> </html>
🌐
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. ... import { HttpParameterCodec } from '@angular/common/http'; export class CustomHttpParamEncoder implements HttpParameterCodec { encodeKey(key: string): string { return encodeURIComponent(key); } encodeValue(value: string): string { return encodeURIComponent(value); } decodeKey(key: string): string { return decodeURIComponent(key); } decodeValue(value: string): string { return decodeURIComponent(value); } }
🌐
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 - 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(); })); }); ... $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 ... This makes testing requests hard as I don't know what to expect as encoded value. Any reason why angular is not using encodeURIComponent?
Author   angular
🌐
StackBlitz
stackblitz.com › edit › angular-url-encode
Angular Url Encode - StackBlitz
Starter project for Angular apps that exports to the Angular CLI
🌐
W3Schools
w3schools.com › jsref › jsref_encodeuricomponent.asp
JavaScript encodeURIComponent() Method
The encodeURIComponent() method encodes special characters including: , / ?
Find elsewhere
🌐
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 › 24754
HTTP GET Query string encoding · Issue #24754 · angular/angular
July 4, 2018 - [ ] Regression (a behavior that ...m/angular/angular/blob/master/CONTRIBUTING.md#question [ ] Other... Please describe: The HttpClient.get() method doesn't encode some characters like '+' and it makes it impossible to pass them as parameters. 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 - Generate the typescript-angular2 client code with the command above and check the ...Api.ts files. ... const path = this.basePath + '{{{path}}}'{{#pathParams}} .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; ... const path = this.basePath + '{{{path}}}'{{#pathParams}} .replace('${' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
Author   swagger-api
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURIComponent
encodeURIComponent() - JavaScript - MDN Web Docs
Use encodeURIComponent() on user-entered fields from forms sent to the server — this will encode & symbols that may inadvertently be generated during data entry for character references or other characters that require encoding/decoding.
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
🌐
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.
🌐
DEV Community
dev.to › wanoo21 › difference-between-encodeuri-and-encodeuricomponent-j3j
Difference between encodeURI and encodeURIComponent - DEV Community
November 4, 2019 - If you're encoding a string to put in a URL component (a query string parameter), you should use encodeURIComponent, and if you're encoding an existing URL, use encodeURI. It's simple!
🌐
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