I have a slight passing understanding of AngularJS but nothing more. I have inherited a java app that is a mix between standard Spring MVC and AngularJS. One of the AngularJS controllers calls a standard MVC controller to get a json data set. When this controller takes too long the angularJS page errors out - presumably a timeout.
I have had a quick look around and it seems to me this is probably a design error and I should do this call further in the controller and use a $then call but I'd like to make as few changes as possible so I thought I'd see if there was a smaller change / better suggestion.
The controller, with the guts ripped out, is like this
'use strict'
var pageController = [
'$scope',
'$http',
'$location',
'$window',
'$filter',
function($scope, $http, $location, $window, $filter) {
$.urlParam = function(name){
...
return val;
}
$http
.get(
"/dataretrievalendpoint?searchparam=" + $.urlParam("searchparam"))
.then(
function(response) {
alert("All is well");
....
},
function(response) {
alert("Error occurred !");
}
);
}
];
So essentially if the .get("/dataretrievalendpoint...) takes too long (seems like milliseconds and on my laptop equates to about 2000 records) it goes to "Error occurred", otherwise "All is well".
Is there a way I can turn the .get into a future or extend the wait time ? or do I need to investigate doing something along the lines of
$scope.param.$then = function(){ return make data retrieval call; }
(AngularJS Controller wait for response (or set callback))
Or should I be doing something else entirely ?!