promise - Preventing Multiple http calls -
i have function calls backend service , data , display in ui. using angular, , function in controller calling html. everytime html gets updated making network call.
i tried add controller level variable check if call in progress if yes return promise or otherwise call again. prevent same calls repeating before first call not finished.
is there other way can handle across project.becuase method have, have write individual functions
my current code follows
var getdatapromise; function getdata() { if (getdatapromise) return getdatapromise; getdatapromise = $http.get('url').then((response) => { return response; }).finally(() => { getdatapromise = null; }) return getdatapromise; }
i want prevent overlapping network calls. becuase data in server can change time time.
one way of preventing multiple http calls cancel previous http call , can this:
test.service('testservice', function ($http,$q) { var canceler; var getlist = function (data) { if (canceler)canceler.resolve(); canceler = $q.defer(); return $http.post('www.test.com', data, {timeout: canceler.promise}); };
Comments
Post a Comment