0

I found lots of posts on this issue and tried to implement some of the solutions proposed here:

But it still does not work and I am wondering if using firebase could be an issue. I have created a service linking to my Firebase datasource:

 servicesModule.factory("postsDB", function($resource){
    return $resource("https://<datasource>.firebaseio.com/Posts/:id", {
        id: "@id"
     },
     {
         update: {
             method: "PUT",
             isArray : true
         }
    });
});

Then my controller:

controllersModule.controller('BlogCtrl', ["$scope", "postsDB", function($scope, postsDB) {

        postsDB.query(function(posts){
             $scope.myPosts = posts;
         })
}]);

The ng-repeat result:

<div class="col s12 m6"  id="postItems" ng-repeat="post in myPosts">
<h3>{{post.Title}}</h3>
{{post.Body}}
{{post.Author}}
</div>

I really do not understand what:

Error: $resource:badcfg Response does not match configured parameter

means (as usual with angular errors) except that it is obviously expecting an array and I though that the whole point of using postsDB.query was to do just that. I have added isArray: true above but it has no effect whatsoever. Why aren't my posts being loaded if the resource exists as a JSON posts array?

Community
  • 1
  • 1
HGB
  • 2,157
  • 8
  • 43
  • 74
  • You added `isArray` to `update`, not to `query`. [See here](http://stackoverflow.com/a/20043070/2163901). Why not use AngularFire or Firebase's libraries?Also, I believe you need to append `.json` to use their REST API. – Anid Monsur Oct 09 '15 at 22:22
  • Hey thanks Anid, you should add your comments as answers so I can accept them. Both adding isArray to query and appending json to the datasource seem to have worked. I am not familiar with Firebase/Angularfire enough yet to know how to implement libraries but will check it out. – HGB Oct 09 '15 at 23:08

1 Answers1

0

Couple things: you need to append .json to the path to use Firebase's REST API and second, you'll need to set isArray: false specifically for the query method.

servicesModule.factory("postsDB", function($resource) {
    return $resource("https://<datasource>.firebaseio.com/Posts/:id.json", {
                id: "@id"
            },
            {
                update: {
                    method: "PUT",
                    isArray: true
                },
                query: {
                    method: "GET",
                    isArray: true
                }
            });
});
Anid Monsur
  • 4,538
  • 1
  • 17
  • 24