title: AngularJS: How to pass values from Controller to Service Method?
body: <p>I have a controller which is dependent on a <code>TransactionService</code>. One of the method is</p>
  
  <pre><code>$scope.thisMonthTransactions = function () {
      $scope.resetTransactions();
      var today = new Date();
      $scope.month = (today.getMonth() + 1).toString();
      $scope.year = today.getFullYear().toString();
      $scope.transactions = Transaction.getForMonthAndYear();
  };
  </code></pre>
  
  <p>The <code>TransactionService</code> looks like</p>
  
  <pre><code>angular.module('transactionServices', ['ngResource']).factory('Transaction', function ($resource, $rootScope) {
      return $resource('/users/:userId/transactions/:transactionId',
          // todo: default user for now, change it
          {userId: 'bd675d42-aa9b-11e2-9d27-b88d1205c810', transactionId: '@uuid'},
          {
              getRecent: {method: 'GET', params: {recent: true}, isArray: true},
              getForMonthAndYear: {method: 'GET', params: {month: 5, year: 2013}, isArray: true}
          });
  });
  </code></pre>
  
  <p>As you can see the method <code>getForMonthAndYear</code> depends on two parameters <code>month</code> and <code>year</code>, which are hardcoded right now as <code>params: {month: 5, year: 2013}</code>. How can I pass this data from my controller?</p>
  
  <p>I tried injecting <code>rootScope</code> in <code>TransactionService</code>, but that did not help(meaning I do not know how to use it probably).</p>
  
  <p>Also <a href="http://docs.angularjs.org/api/ngResource.%24resource">Angular ngResource documentation</a> doesn't recommend any way to perform this. </p>
  
  <p>Can someone please guide here?</p>
  
  <p><strong>UPDATE</strong><br>
  My Controller looks like</p>
  
  <pre><code>function TransactionsManagerController($scope, Transaction) {
  
      $scope.thisMonthTransactions = function () {
          $scope.resetTransactions();
          var today = new Date();
          $scope.month = (today.getMonth() + 1).toString();
          $scope.year = today.getFullYear().toString();
  
          var t = new Transaction();
          $scope.transactions = t.getForMonthAndYear({month: $scope.month});
      };
  }
  </code></pre>
  
  <p>and I change service method to </p>
  
  <pre><code>getForMonthAndYear: {method: 'GET', params: {month: @month, year: 2013}, isArray: true}
  </code></pre>
  
  <p>I look at the <code>console.log</code> and it says</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token ILLEGAL transaction.js:11
  Uncaught Error: No module: transactionServices 
  </code></pre>