title: How to pass ampersand (&) to AngularJS resource parameter
body: <p>I have an angular resource declared as follows</p>
  
  <pre><code>angular.module('xpto', ['ngResource'])
  .factory('XPTO', function ($resource, $location) {
      var XPTO = $resource($location.protocol() + '://' + $location.host() +
      ':port' + '/myservice.svc/gerencia?sigla=:sigla',
          {
              port: ':' + $location.port()
          }
      );
      return XPTO;
  })
  </code></pre>
  
  <p>and I would like to call the service passaing a parameter that contains an ampersand (&amp;), something like:</p>
  
  <pre><code>XPTO.query({ sigla: 'abc&amp;d' }, function (gerencias) {
  $scope.gerenciasBuscadas = gerencias;
  });
  </code></pre>
  
  <p>However, AngularJS does not encode the &amp; properly. It sends "sigla=abc&amp;d" instead of "sigla=abc%26d" , causing my server to see the query string parameter value for "sigla" as being just "abc", instead of "abc&amp;d".</p>
  
  <p>Looking into angular-resource-1.0.7.js, I saw the following: </p>
  
  <pre><code>/**
   * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
   * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
   * segments:
   *    segment       = *pchar
   *    pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
   *    pct-encoded   = "%" HEXDIG HEXDIG
   *    unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
   *    sub-delims    = "!" / "$" / "&amp;" / "'" / "(" / ")"
   *                     / "*" / "+" / "," / ";" / "="
   */
  function encodeUriSegment(val) {
    return encodeUriQuery(val, true).
      replace(/%26/gi, '&amp;').
      replace(/%3D/gi, '=').
      replace(/%2B/gi, '+');
  }
  </code></pre>
  
  <p>So, it will encode '&amp;' and decode it back before it sends the request to the server. Is there any point where I could customize the url right before it is sent to the server? Changing encodeUriSegment is an option, but it might break other stuff inside Angular. Any ideas?</p>