I have a controller function as follows
function UserDetailsControl($scope, $routeParams, UserService) {
$scope.user = UserService.get({id: $routeParams.id});
alert($scope.user.phone);
}
When i access the user variable in templates it looks something like the following:
{
"website_name": null,
"email": "Monroe@Chamorro.com",
"first_name": "Monroe",
"id": "31",
"last_name": "Chamorro",
"phone": 2147483647,
}
but alert($scope.user.phone); this always returns undefined. why ? No matter what element i try to access it always returns undefined.
It happens since the $resource is asynchronous. Check this thread for detailed explenations: How does the $resource `get` function work synchronously in AngularJS?