While in angularjs

0

I need advice on the following problem:

I am working on a number taking software, I have two instances of work. One is the Totem that is where I ask, I take, I acquire my number to be served and the other is the control panel, a Web-app that is where I call the number to attend ...

in this case I have the problem in the web-app:

Here I need to update the current attention number and the list of waiting numbers every time I call a number to assist you ...

The problem is that the answer is asynchronous, it can take 5 sec as 3 sec ... to bring me the changes to show them in the front. So when I click on call it does not help me to put the functions of updating to the new numbers because it will plow it before the answer and the change will not be made ...

Solutions?

First I thought about using a $timeout of 3 sec but being asynchronous does not work for me and putting more time is already latoso ...

Now it occurred to me to do a kind of while that means that when you press the call button, you are constantly asking about the function that brings the current attention number ( $scope.cola() ) if it is different than update the data ( $scope.actualizar() ) and cut the while otherwise continue to find difference ...

I have $scope.cola() a function that brings:

  

Letter
  CurrentNumber

and $scope.actualizar() that you run:

  

$scope.cola() (brings the current number of attention)
$scope.tickets() (brings the numbers that are waiting)

$scope.cola() mas simplificado seria:


   $scope.Cola = function(){

 Ticket.Colaservices({

  id_usuario: LoginData.getData().id_usuario,
  token: LoginData.getData().token,
  id_sucursal: LoginData.getData().id_sucursal,
  id_moduloatencion: LoginData.getData().moduloatencion_id

}, function(response){

  $scope.DateCola = response.data;
   var numeroAct = response.data.numero
   window.localStorage.setItem('number', numeroAct);
});

}

Here in the answer function I keep the current letter in the variable numeroact and the store in a localStorage .

In my function call would be:

  $scope.llamar = function(){

   var num = window.localStorage.getItem('number');

   Llamado.Llamar({
   id_usuario: LoginData.getData().id_usuario,
   token: LoginData.getData().token,
   id_sucursal: LoginData.getData().id_sucursal,
   id_moduloatencion: LoginData.getData().moduloatencion_id
 },function(response){

   necesito estar ejecutando en un bucle $scope.cola() hasta que num      cambie y y cuando lo haga ejecute $scope.actualizar()

})   }

Please help and thank you.

    
asked by Hernan Humaña 02.03.2017 в 18:34
source

2 answers

0

Your solution is $ interval

let resultado = $interval(function() {
            let esMantequilla = false;
            //lo que quieras
            if(esMantequilla){
              $interval.cancel("valor de retorno si lo deseas");
            }
          }, 100);

the number 100 is the delay (delay) that will be executed by function

    
answered by 02.03.2017 в 19:23
0

I think what you need would be to use promise .

Take a look that there is a lot of documentation about it. link

Basically you can launch a request and wait for an answer to launch the next operation. So you would call the function that gives you the new ticket and when you finish you would call the update.

    
answered by 03.03.2017 в 12:16