У меня есть контроллер, который зависит от TransactionService
. Один из методов -
$scope.thisMonthTransactions = function () {
$scope.resetTransactions();
var today = new Date();
$scope.month = (today.getMonth() + 1).toString();
$scope.year = today.getFullYear().toString();
$scope.transactions = Transaction.getForMonthAndYear();
};
TransactionService
выглядит как
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}
});
});
Как вы можете видеть, метод getForMonthAndYear
зависит от двух параметров month
и year
, которые теперь жестко запрограммированы как params: {month: 5, year: 2013}
. Как передать данные с моего контроллера?
Я попробовал вставить rootScope
в TransactionService
, но это не помогло (это означает, что я не знаю, как его использовать).
Кроме того, Angular документация ngResource не рекомендует никакого способа выполнить это.
Может ли кто-нибудь обратиться сюда?
UPDATE
Мой контроллер выглядит как
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});
};
}
и я меняю метод службы на
getForMonthAndYear: {method: 'GET', params: {month: @month, year: 2013}, isArray: true}
Я смотрю на console.log
, и он говорит
Uncaught SyntaxError: Unexpected token ILLEGAL transaction.js:11
Uncaught Error: No module: transactionServices