0

This is possibly just the way I am accessing the resource object but I have the service below:

angular.module('appointeddPortalApp')
.factory('Salon', function ($resource) {
    // Service logic
    // ...

    // Public API here
    return $resource('http://api.appointeddcore.dev/organisation/:id', {id: '@id'}, { 
        update: { method: 'PUT' }, 
        query: { method: 'GET', isArray: false} 
    });
});

I'm using the query method like this:

var data = Salon.query($scope.options);
console.log(data);

From the console.log() :

Resource {$get: function, $save: function, $query: function, $remove:
function, $delete: function…} 
offices: Array[20]
total: 33
__proto__: Resource

My problem is trying to access total or offices I get undefined

console.log(data.total); // undefined

1 Answer 1

4

Because Salon.query() returns immediately with an empty object and updates the variable data if the data is present, try this:

var data = Salon.query(function(callbackdata){
   //function is called on success
   console.log(callbackdata);
   console.log(callbackdata.total);
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.