Edit: Apologies to the answerers, it turns out that this was actually valid code, but requests were being intercepted and stripped of all of the parameters.
I'm trying to make repeated HTTP GET requests to a REST API, depending on the output and have used the solution from this question.
However, I wish to increment one of the parameters that I pass in the request. Essentially, the API pages the output and I need to increase the value of startAt accordingly.
Manual requests work fine with:
<URL>/board?startAt=50
And give back:
{"maxResults":50,"startAt":50,"isLast":true,"values":[list_of_values]}
Here's my code so far:
function getHttpPromise(start_at) {
// This function recurses until the server returns isLast = true.
//
// Each iteration appends the values in response.values to
// $scope.boards.
test = $http({
url: 'boards',
method: 'GET',
params: {'startAt': start_at.toString()}
}).
success(function (response) {
console.log(response); // the response contains startAt, which always has
// the initial value (0), rather than start_at's value
var values = response.values;
for (var i in values) {
var board = values[i];
$scope.boards[board.id] = board;
}
if (response.isLast) {
// We have received all the boards.
return true;
} else {
// Increment start_at and return another http request promise.
start_at += response.maxResults;
return getHttpPromise(start_at);
}
}
);
console.log(test); // params is correct here
return test;
}
This function is called by:
jiraWorkLog.controller('SprintSelectCtlr',
function($scope, $http, $routeParams) {
$scope.init = function() {
$scope.boards = new Object();
getHttpPromise(0).then(
function (dummy_var) {
for (var board in $scope.boards) {
...
}
}
);
}
...
);
console.log(response.maxResults);before adding it tostart_at? What do you see in the when you doconsole.log(start_at);before and after the value is incremented?response.maxResults=50andstart_at=0 => start_at=50etc.). @Aravind I edited my question accordingly. It's in ourSprintCtlrobject.