I am struggling over the past day with some strange situation. What happens is that duplicate requests are sometimes sent for an API HTTP request on a remote server. Can someone provide help on how to avoid these duplicate requests?
Here is an example of the function I use in the factory:
factory.getAllConsultedClientsLogs = function(oParams) { var deferred = $q.defer(); $http.post('url/to/api', oParams) .success(function(response) { deferred.resolve(response); }) .error(function() { deferred.reject("Error! @factory.getAllConsultedClientsLogs"); }); return deferred.promise; };
... and an example of a function using the above on the controller:
$scope.openConsultedClientsLogsModal = function(operator, date) { if (angular.isDefined(operator) && angular.isDefined(date)) { RrAuditingFactory.getAllConsultedClientsLogs({'operator':operator,'date':date}).then(function(promise) { if (angular.isObject(promise) && angular.isDefined(promise.error) && promise.error == 0) { var modalInstance = $modal.open({ templateUrl: 'path/partial', controller: function($scope, $modalInstance, logsResult) { $scope.logsResult = logsResult; }, resolve: { logsResult: function() { return promise.result; } } }); modalInstance.result.then(function() { }, function () { }); } else { ErrorContext.setError(promise.errorMsg); } }, function(promise) { ErrorContext.setError(promise); }); } else { ErrorContext.setError(); } };
Thanks in advance. Hope someone can help me ...
source share