How to use the While with a Service AngujarJs


I have the following problem, I hope you can help me.

I have a while loop and inside I am calling a service, the problem is that the loop runs many times and never enters the service, blocks the browser and does not enter the service, if I remove the while if it enters. You know what I'm missing?

while (termina === false) {
      .then(function (data) {
        if (data !== '' && moment(vm.detalle.HeFecha, 'YYYY-MM-DD').day() === 0) {
              domingo = 'S';

That is a part of the code, I do not hit everything because it is mut long, the fact is that it does not come to call the service, I greatly appreciate help or guidance in this process.

asked by Cristian 31.08.2016 в 03:04

1 answer


Remember that the invocation is asynchronous, it is invoked and the execution continues until the service responds by entering the then (), therefore you can have several calls in parallel

That is, when using a while you were able to make several invocations and after several cycles receive the first answer.

answered by 31.08.2016 / 04:50