AngularJs Encode URL

AngularJs Encode URL Example : We can use the javascript inbuilt function encodeURIComponent(string), encodeURI(string) or escape(string) to encode the url string. Here in this tutorial we are going to explain how you can encode url string with example and online demo.

AngularJs Encode URL Parameters | String | JavaScript | Example

Let us create a simple example to use the function encodeURIComponent(string) to encode the url parameters.

AngularJs Encode URL Parameters: Example

<!DOCTYPE html>
<html lang="en">
 <script src="//"></script>
 var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
  $scope.url1 = '';
  $scope.url2 = '';
  $scope.encodeUrlStr = function() {
   $scope.url2 = "" + encodeURIComponent($scope.url1);
<div ng-app="myApp">  
<div ng-controller="myController">  
    <button ng-click ="encodeUrlStr()" >Encode URL</button>
	URL1 = {{url1}}<br>
	URL2 = {{url2}}

Try it »

If you run the above example it will produce output something like this –

AngularJs Encode URL


Keep in mind the difference between the three functions before using them.

  • escape(): This will not encode: @*/+
  • encodeURI(): This will not encode: ~!@#$&*()=:/,;?+’
  • encodeURIComponent(): This will not encode: ~!*()’


Add Comment

📖 Read More