I have a function inside a angular js controller. I try to do a while cycle but the stop condition is a result of a promise that I execute in a service. The result is that the cycle is infinity.
My code:
$scope.origin = "table_name";
$scope.start = 1;
$scope.end = new Date().getTime();
$scope.setData = function () {
var flag = true;
while(flag)
{
service.getData($scope.origin, $scope.start, $scope.end, 0, 100)
.then(
function(res)
{
if(res.length == 100)
{
$scope.start = res[res.length - 1].timestamp;
}
else
{
flag = false;
}
},
function(err)
{
flag = false;
}
);
}
}