0

Trying to get ngResource to work, but getting the error:

Object # has no method 'query'

I've tried to keep it as simple as possible and according to the documentations/posts that I can find, this should work. But it doesn't.

Here's my service/factory:

var srcServices = angular.module('srcServices', ['ngResource']);

srcServices.factory('Rotation', ['$resource',
  function ($resource) {
    return $resource('/rotations/:id' );
  }]);

And here's the controller code triggering the error:

var srcControllers = angular.module('srcControllers', ['ngResource']);

srcControllers.controller('RotationListCtrl', ['$scope', '$location', 'Rotation', function($scope, Rotation, $location) {

  Rotation.query(function(data) {$scope.rotations = data;})

  $scope.edit = function(a) {
    var path = "/rotations/" + a._id.$oid;
    $location.path(path);
  };
}]);
jkbradshaw
  • 25
  • 5
  • 1
    For minification, dependency injections has to be in the same order. `srcControllers.controller('RotationListCtrl', ['$scope', '$location', 'Rotation', function($scope, $location, Rotation) { } `. Note `$location` is 2nd param and `Rotation` is 3rd. – dmahapatro Apr 04 '14 at 06:13
  • This worked even though I'm not using minified js. Thanks! – jkbradshaw Apr 04 '14 at 16:57

1 Answers1

0

Try this

var srcControllers = angular.module('srcControllers', ['ngResource', 'srcServices']);

You are creating the service as a new angular module. So in order to get access to the service you have to inject it to your controller.

BKM
  • 6,949
  • 7
  • 30
  • 45