-1

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> 
Alex Kibler
  • 4,674
  • 9
  • 44
  • 74
  • Seems like just a Typo. Explicit annotation list (`'CartResource','cart'`) and argument list of the constructor (`loginController(cart, CartResource) `) must be in the same order, in your case they are reversed – PSL Aug 31 '15 at 15:26
  • Hmm, I fixed the order, but that actually didn't fix it. I'm still getting `CartResource.get is not a function`. I updated the OP to have the fixed order – Alex Kibler Aug 31 '15 at 15:30
  • Log `CartResource` - what's it show? – tymeJV Aug 31 '15 at 15:35
  • [Here is a Fork of your code](http://plnkr.co/edit/1zwXhn?p=preview), but without the `car` injection since we don't known what is. And it works just fine – Matias Fernandez Martinez Aug 31 '15 at 15:39
  • Hm, you're right. Taking out the reference to cart does seem to make it work. I also tried putting cart last and that also seemed to fix it. Strange. – Alex Kibler Aug 31 '15 at 15:47

1 Answers1

0

Somehow changing the order of the dependencies seemed to fix it. Sadly I don't have anything more specific to add.

Alex Kibler
  • 4,674
  • 9
  • 44
  • 74