AngularJs Decode URL


AngularJs Decode URL String Example : We can use the javascript inbuilt function decodeURIComponent(uri), encodeURI(uri) or escape(uri) to decode the uri string. Here in this tutorial we are going to explain how you can decode the uri string with example and online demo.


AngularJs Encode URL| URI Component | JavaScript | Example

Let us create a simple example to use the function dcodeURIComponent(uri) to decode the uri component.

AngularJs Decode URI Component: Example

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
 var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 
  $scope.url1 = ' http://demo.com/index.php?url=http%3A%2F%2Fdemo.com%2Findex.php%3Fparam1%3Djohn%26param2%3Ddoe';
  $scope.url2 = '';
  $scope.encodeUrlStr = function() {
   $scope.url2 = "http://demo.com/index.php?url=" + decodeURIComponent($scope.url1);
  }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
    <button ng-click ="encodeUrlStr()" >Decode URL</button>
	<br>
	URL1 = {{url1}}<br>
	URL2 = {{url2}}
</div> 
</div>
</body>  
</html>                                                                                                                

Try it »

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

AngularJs Encode URL| URI Component | JavaScript | Example


Advertisements

Add Comment

📖 Read More