On this site Andrew McGivery I found this very interesting example:
.controller('UserCtrl', function($scope, $stateParams, userService) {
var user = userService.getUser($scope.id);
})
.factory('userService', function($http) {
var users = [];
return {
getUsers: function(){
return $http.get("https://www.yoursite.com/users").then(function(response){
users = response;
return users;
});
},
getUser: function(id){
for(i=0;i<users.length;i++){
if(users[i].id == id){
return users[i];
}
}
return null;
}
}
})
I would like to know how I would return all users if I had more than one user with the same id?