$scope.$apply is what is necessary when you use stuff that isn't from Angular
Because Angular runs in its own event loop, if you use stuff like XHR (like Ismael suggested), Angular isn't going to detect the change and thus the controller won't be updated
That's why you use $http - or, alternatively, $scope.$apply
a promise is an object that represents an asynchronous operation
$http.get returns a promise.
If you have multiple promises that you want to wait to be finished for you use $q.all(arrayOfPromises) and then the then callback will be invoked
A promise has a couple of methods on them, but the main ones are then, catch and finally
each of them takes a callback and each of those callbacks are invoked at different points.
the then calback is invoked when the promise fulfills itself (finishes the operation with no errors) with the result of the operation. In this case, then will contain a XHR response object.
catch is invoked when there is an error in either the asynchronous operation or in the then callback.
finally is called regardless of then or catch.
So, your code should be $http.get('/someUrl').then(function(response) { $scope.data = response.data; });
I've got an array, and I need to assign them all position values 1->6, back to 1, start again kinda process
function convert (data) {
if (typeof data != 'object'){ throw new TypeError("Input parameter needs to be an object");}
var dataWithAttributes = [],
position = 1;
data.forEach(function (elem) {
dataWithAttributes.push({
name: elem,
pos: position
});
position == 6 ? position= 1 : position++;
});
return dataWithAttributes;
}