1

I've got a bit of a pickle that I hope you can help out with. I'm, working on making an Ionic version of an Angular web application that I have recently build. Since it is essentially the same angular between the two, you would think they would react the same, but here's where to goes wrong...

This is my Angular resource factory...

.factory('applicationFactory', ['$resource', 'AuthFactory', '$rootScope', function ($resource, AuthFactory, $rootScope) {
    return $resource($rootScope.serverURL + "applications", {},
        {
            'query': {
                method: 'get',
                isArray: true,
                headers: {'auth-token': AuthFactory.authToken}
            }
        });
}])

And this is my controller that calls it...

 .controller('ApplicationController', ['$scope', '$rootScope', '$state', 'applicationFactory', 'AuthFactory', function ($scope, $rootScope, $state, applicationFactory, AuthFactory) {

    $scope.applications = applicationFactory.query();

This combination ends up yielding this error:

ionic.bundle.js:25642 Error: [$resource:badcfg] Error in resource configuration for action `get`. Expected response to contain an object but got an array (Request: GET https://communityservermanager.herokuapp.com/applications)

As you can see I have clearly marked the isArray configuration option as true. Also as I said before this is directly copied and pasted from an existing angular application, where it works just fine. What the heck am I doing wrong!?!?

Thanks in advance for the help :)

mcheli
  • 35
  • 1
  • 6
  • Can you try changing `isArray` to `false` as `isArray: false` in your `factory` code? – David R Oct 01 '16 at 17:00
  • Sure! So just changed it and ended up getting the same error. It seems like the configuration just isn't being applied. However, I can see in the request headers that I am providing the auth-token, so I know that's at least working. – mcheli Oct 01 '16 at 17:07

1 Answers1

0

Whelp, I'm an idiot! The answer is that I actually had two controllers named ApplicationController. This was causing the error on another controller that had incorrect syntax. My b.

mcheli
  • 35
  • 1
  • 6