In my app, I define a cart resource
.factory('CartResource', function ($resource) {
return $resource('/api/Cart/:id');
});
on the module. In my logincontroller,
(function () {
"use strict";
angular.module('ShoppingCart')
.controller('loginController', ['CartResource','cart', loginController]);
function loginController(CartResource, cart) {
var vm = this;
vm.model = cart.model;
vm.login = login;
function login(username, password) {
CartResource.get({ username: username, password: password }, function (data) {
console.log(data);
})
}
};
}());
I am injecting the CartResource and trying to get a user object by passing a username and password. However, whenever I call login()
, it says that CartResource.get
is not a function. What am I doing wrong? I'm doing almost this exact same thing in another application but it doesn't seem to work here. Is there something wrong with the order in which I include my script files in my index.html
?
<script src="app/app.module.js"></script>
<script src="app/app.config.js"></script>
<script src="app/controllers/services/Cart.resource.js"></script>
<script src="app/controllers/loginController.js"></script>
Somehow changing the order of the dependencies seemed to fix it. Sadly I don't have anything more specific to add.