I need to access attributes of an object that originates from a $resource factory service (REST API).
services.js:
myApp.factory('userService', ['$resource', 'backendUrl', function($resource, backendUrl) {
return $resource(backendUrl + '/api/users/:region/:name',
{region: '@region', name: '@name'}
);
}]);
controllers.js:
$scope.userInfo = userService.get({region: $routeParams.region, name: $routeParams.name});
When I use console.log($scope.userInfo)
in controllers.js, the userInfo
object displays several attributes. However, I am facing difficulties accessing these attributes using dot or bracket notation.
Sample output of console.log($scope.userInfo)
:
Resource {$promise: Object, $resolved: false, $get: function, $save: function, $query: function…}
$promise: Object
$resolved: true
id: 185
last_update: "2014-08-13T08:56:19.546"
name: "test_user"
region: "na"
Even though I see the above output, trying to access something like $scope.userInfo.name
returns undefined
. I require some of this information from userInfo
for creating subsequent requests to the API.
Is there something specific about this being a Resource type object that I am missing?