I've a controller, where the flow should go sequentially. I'm making an $http GET request, and it should wait for getting the response and then it should go forward. Rather it completes the flow, and at the end it gets the response. How can I stop it?
Here is the code
function CarouselDemoCtrl($scope,$http) {
$scope.slides = [];
console.log("1")
$http.get('data.json').
then(function(response) {
$scope.slides = response.data.slides;
console.log("done");
});
console.log("2");
}
It prints "1,2 and then "done". Where it should follow as "1,done and 2"
The code snippet is like this
function CarouselDemoCtrl($scope,$http) {
$scope.slides = [];
console.log("1");
$http.get('data.json').
then(function(response) {
$scope.slides = response.data.slides;
console.log("done");
});
$scope.myInterval = 7000;
console.log($scope.slides);
var i, first = [],second, third;
var many = 1;
//##################################################
//Need to be changed to update the carousel since the resolution changed
$scope.displayMode = "tablet";
//##################################################
if ($scope.displayMode == "mobile") {many = 1;}
else if ($scope.displayMode == "tablet") {many = 2;}
else {many = 3;}
for (i = 0; i < $scope.slides.length; i += many) {
second = {
image1: $scope.slides[i]
};
if (many == 1) {}
if ($scope.slides[i + 1] && (many == 2 || many == 3)) {
second.image2 = $scope.slides[i + 1];
}
if ($scope.slides[i + (many - 1)] && many == 3) {
second.image3 = $scope.slides[i + 2];
}
first.push(second);
}
$scope.groupedSlides = first;
}