0

I'm using external mongodb and wrote a node/express server for fetching the data on my localhost.

I query localhost like this:

http://localhost:8888/api/bonsais

And I'm getting the correct results from my mongodb collection @ mongolab.

[{"name":"test,test2","_id":"536be2e2ae54668818000001","__v":0},{"name":"testname","_id":"536fd2df41f84a581c000001","__v":0}]

I wrote a service to fetch the data like this:

angular.module('bonsaiService', ['ngResource']).
  factory('bonsaiService', function($resource) {
  return $resource('http://localhost:8888/api/bonsais',{'query': {method: 'GET', isArray: true }});
});

I'm getting a Error: [$resource:badcfg] object, which is referring to these error docs

Stennie
  • 63,885
  • 14
  • 149
  • 175
Martijn.Veenstra
  • 121
  • 1
  • 2
  • 7

2 Answers2

0
.factory('Bonsai', function($q, $resource){
    var bonsaiResource = $resource('http://localhost:8888/api/bonsais', {}, {
        get: {
            method: 'GET',
            isArray: true
        }
    });

    return {
    get: function() {
      var q = $q.defer();

        bonsaiResource.get({
        },
        function(resp) {
            q.resolve(resp);
        }, function(httpResponse) {
            q.reject(httpResponse);
        });

        return q.promise;
    } };
})

try to write it this way. Then you can call it with Bonsai.get()

thesearentthedroids
  • 588
  • 1
  • 7
  • 24
0

Thanks @thesearentthedroids, your responds fixed it for me!

Just to follow up, I've used the following to retrieve the data in my controller:

bonsaiService.get($scope.trees).then(
    function(data){
        $scope.trees = data;
});
Martijn.Veenstra
  • 121
  • 1
  • 2
  • 7