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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -