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?

2
  • You added isArray to update, not to query. See here. Why not use AngularFire or Firebase's libraries?Also, I believe you need to append .json to use their REST API. Commented Oct 9, 2015 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. Commented Oct 9, 2015 at 23:08

1 Answer 1

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
                }
            });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.