Reputation: 83
$http({
url: "php/load.php",
method: "GET",
params: {'userId':userId}
}).success(function(data, status, headers, config) {
$scope.data = data;
}).error(function(data, status, headers, config) {
});
$scope.data[0]= "something";
How to wait above ajax to finish loading then load $scope.data[0]= "something";? I tried to place it within the $http and below $scope.data=data but it seem to have collision still..
Upvotes: 0
Views: 132
Reputation: 1917
var promise1 = $http({
url: "php/load.php",
method: "GET",
async: false,
params: {'userId':userId}
});
$.when(promise1).then(
function(data, status, headers, config) {
$scope.data = data;
},
function(data, status, headers, config) {
}
).done(function() {
$scope.data[0]= "something";
});
Haven't tested, but that should be right. Look into jQuery.when() and jQuery.promise() if not.
Upvotes: 1