title: Pass argument from controller to service with Angular
body: <p>I have a service which performs an HTTP call and gets some data to a particular URL.
  What I am trying to do is to pass an argument from the Controller to the Service and use it as parameter in my URI.</p>
  
  <p>For example, my call now is api.myurl.com/foo and I want to make it api.myurl.com/foo/bar</p>
  
  <p>Where <em>bar</em> is user's input from a search form.</p>
  
  <p>At the moment, my code looks like this:</p>
  
  <p><em>Service</em></p>
  
  <pre><code>angular.module('MyApp').service('MyMapper', function(MyService, $http, $q, API_TR_URL, _, PAGINATION_LIMITS) {
  function MyMapper() {}
  
      MyMapper.prototype.find = function(params) {
      var p = angular.copy(params);
      p.limit = PAGINATION_LIMITS.myResolver;
      var d = $q.defer();
  
      var requestURL = API_TR_URL + '/app_dev.php/entities/' + param;
  
          $http.get(requestURL)
          .success(function(results)
          {
              console.log('Results data  entities: ', results.data.data.entities);
             for (var entitiesIndex in results.data.data.entities)
             {
                 var preparedData = results.data.data.entities[entitiesIndex];
                 results.data.data.entities[entityIndex] = new Entity(preparedData);
             }
  
             d.resolve(results);
          })
          .error(function(status)
          {
              d.reject(arguments);
          });
  
      return d.promise;
      };
  
  return new MyMapper();
  });
  </code></pre>
  
  <p>and the <em>Controller</em> like this:</p>
  
  <pre><code>angular.module('MyBackendApp')
  .controller('MySearchFormController', ['$scope', 'API_TR_URL', 'MyMapper', '$location', function($scope,  MyMapper, $location){
      $scope.submit = function (){
  
              console.log('-- Search string: '+ $scope.entityName);
  
              var entitiesCount = Object.keys(data.data.data.entities).length;
              $scope.totalPagesNum = Math.ceil( entitiesCount / 10);
              $scope.page = data.page;
  
              var d = $q.defer();
  
              // Build the  results
              $scope.entitiesResults = (function listEntities(entities, $scope){
  
                  var entities = data.data.data.entities;
  
                  if ( (typeof entities === 'undefined') || (entities.length === 0) ){
                      return null;
                  }
  
                  return entities;
              })();
  
  
      }
  }
  
  ]);
  </code></pre>