USE CASE:
I have to do 3 async request when presenting the page, if you click in a
button i have to call the same 3 request but with different GET params
When each of the requests resolves, I uses $scope.list.push(); because I
need to show only those request that resolved OK because of those 3 request
it is possible that 1 or more fails.
I have some cases that it just takes too long to resolve and if you click
on the button again this is what happens:
original:
/url1 RESOLVED
/url2 RESOLVED
/url3 WAITING ....
click on my button after X seconds:
/url4 RESOLVED
/url5 RESOLVED
/url6 RESOLVED
/url3 RESOLVED (it was pending but it resolved after I click)
So I get an array with 3 OK data and 1 of the previous data.
My code:
$scope.cotizar = function () {
$scope.cargando = true;
$scope.cotizaciones = [];
$http.get("/aseguradora1/cotizar?" +
jQuery.param($scope.data),{timeout: 10 *1000})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
$http.get("/aseguradora2/cotizar?" +
jQuery.param($scope.data),{timeout: 10 *1000})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
$http.get("/aseguradora3/cotizar?" +
jQuery.param($scope.data),{timeout: 10 *1000})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
};
$scope.cotizar();
I tried something like this but the thing is if I call canceller.resolve()
right after the method call, it wont even do the requests:
$scope.cotizar = function () {
var canceller = $q.defer();
*canceller.resolve(); //it wont even let the following
requests instead of cancelling the previous ones*
$scope.cargando = true;
$scope.cotizaciones = [];
$http.get("/aseg1/cotizar?" +
jQuery.param($scope.data),{timeout: canceller.promise})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
$http.get("/aseg2/cotizar?" +
jQuery.param($scope.data),{timeout: canceller.promise})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
$http.get("/aseg3/cotizar?" +
jQuery.param($scope.data),{timeout: canceller.promise})
.success(function (response) {
$scope.data.cobertura2 = $scope.data.cobertura;
$scope.data.deducibles2 =
$scope.data.deducibles;
$scope.cotizaciones.push(response);
}).then(function (){
$scope.cargando = false;
});
};
$scope.cotizar();
Is there something like $http.cancelAll();?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.