i have a service witch retrieves users from my backend application, but it returns an empty array when there is some data. Here is code:
var service = this;
service.users = [];
service.getUsers = function()
{
$http(
{
method: 'GET',
url: 'http://api.svcassist.dev/index.php/v1/user'
}
).then(
function( data )
{
angular.forEach( data.data.data, function( value, key)
{
service.users.push(
{
id: value.id,
first_name: value.first_name,
last_name: value.last_name,
email: value.email
}
);
});
return service.users;
},
function( error ){}
);
return service.users;
};
getUsers() function returns empty array, but when i log data in forEach loop i see that there are some data that are pushed to array. I have a lot more services that works exactly like this, i cant figure out whats wrong here.