I'm trying to wrap my head around promises in angular and i have the example below that I'd like to convert to use promises so hopefully it will help me go "Ah ha!".
All the examples that I find on the interwebs are using services/factories/etc and I just want to know the best way to make something simple like this use promises.
angular.module('web').controller('CardsCtrl',function($scope, $http, $q){
// Don't worry about how the variable "users" gets populated, let's just say it came into magical existance from a unicorn's horn.
$scope.users = users;
// Loop through all the users
for(var i = 0; i < $scope.users .length; i++) {
// THIS FAILS BECAUSE THE LOOP FINISHES BEFORE THE 1ST GET REQUEST FINISHES SO WE CAN'T REFERENCE THE I VARIABLE
$http.get('http://uifaces.com/api/v1/random', function(face) {
$scope.users[i].face = face.image_urls.mini;
});
}
});