2

New to Angular -

Using $resource to query all records from a MongoDB model using mongoose. Does not execute callback. Explain how to set this up.

Here's the controller code.

MyService.recordCount.query( function(response){
    console.log(response); // -----> Does not execute
    $scope.count = response.length;
});

Service code is:

angular.module('myModule').factory('MyService', ['$resource',
    function($resource) {
        return {
            recordCount:
                $resource('/mymodule/recordCount'),
        };
    }
]);

Note: The DB call returns appropriate data, but controller code fails to call the callback in query().

Please explain why.

2
  • 2
    Are you sure the call is successful? Have you tried setting an error callback to check that? Try MyService.recordCount.query({},angular.noop,function () {console.error(arguments)}); Commented Jul 26, 2014 at 8:55
  • Did you add angular-resource.js and ngResource dependencies to your app? Are there any errors in console? Commented Aug 19, 2014 at 20:47

0

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.