how to use angular resource sails?
Check this part of the documentation: https://github.com/angular-resource-sails/angular-resource-sails#success-and-error-callbacks
If you want to access the data you fetched, you'll probably have to provide the query function with callbacks. So your code would become
sailsResource('roles').query(function(items) { // GET /item $scope.roles = items; angular.forEach($scope.roles, function(value, key) { console.log(key + ': ' + value); });});
The query
method is asynchronous. sailsResource
creates $resource
API compatible services so you have to do your looping in a callback function.
For example
$scope.roles = sailsResource('roles').query(function(roles) { angular.forEach(roles, function(value, key) { // and so on });});
You can also use the $promise
property to access the promise, eg
$scope.roles = sailsResource('roles').query();$scope.roles.$promise.then(function() { angular.forEach($scope.roles, function(value, key) { // etc });});