AngularJS Tutorial - Filter to encode URL








The following code shows how to use Filter to encode URL.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
var app = angular.module('app', []);
app.filter('encodeURIComponent', function() {
    return window.encodeURIComponent;<!--   w  w  w  .  j a v  a  2s . co  m-->
});
</script>
</head>
<body>
  <div ng-app="app"><a href="/foo/{{ 'bar&baz' | encodeURIComponent }}">Test</a>
  </div>
</body>
</html>

The code above is rendered as follows: