doubts about a promise and for Angularjs

0

The problem I have is that I first do a cycle where I fill an object that later sends the post request, the bad thing is that the promise is executed at the end of the for cycle and not one by one as it should be. Any ideas?

?
for (var i = 0; i <= vec.length-1;i++) {
              parrafo = vec[i];
              if (parrafo.substring(0, 1) != "*") {
                  // swal("imprimiendo codigos", "info");
                  $scope.txtSkuinicial = parrafo.trim();
                  $scope.txtSkufinal = parrafo.trim();

                  //objetos capturados
                   objskuinicial = $scope.txtSkuinicial;
                   objskufinal = $scope.txtSkufinal;
                   objcheckprecio = $scope.chbox.cb1;
                   objcheckpieza = $scope.chbox.cb2;
                   Accion = "1";
                   objtamano = $scope.tamanoseleccionado;
                   objprecio = $scope.precioseleccionado;
                   objimpresora = $scope.ListaImpseleccionada;
                   objprecios = $scope.precioseleccionado;
                 //parametros a mandar al store
                   TipoImpresion = objtamano.Id_Etiqueta;
                   SKUinicial = objskuinicial;
                   SKUFinal = objskufinal;
                   ListaTda = "3";
                   ListaPrecios = objprecios.Valor;
                   ListaMay = "4"
                   Impresora = objimpresora.nombreimpresora;
                   PorPieza = "";
                   labels = objtamano.No_Filas;
                  if (objcheckpieza == true) { PorPieza = "1"; } else { PorPieza = "0" }
                   ConPrecio = "";
                   if (objcheckprecio == true) { ConPrecio = "1"; } else { ConPrecio = "0" }
                    impresion = { Accion, TipoImpresion, SKUinicial, SKUFinal, ListaTda, ListaMay, PorPieza, ConPrecio, Impresora, labels, ListaPrecios };
                    datosimpresion.push(impresion);
              } else {//para cuando la linea tieneasterisco
                  $scope.txtSkuinicial = "*"
                  $scope.txtSkufinal = parrafo;
                  var sinasterisco = $scope.txtSkufinal;
                  var separador = "*";
                   var arreglo = [];
                  arreglo = sinasterisco.split(separador)
                    $scope.txtSkufinal = arreglo[1].trim();
                   //objetos capturados
                  objskuinicial = $scope.txtSkuinicial;
                   objskufinal = $scope.txtSkufinal;
                   objcheckprecio = $scope.chbox.cb1;
                   objcheckpieza = $scope.chbox.cb2;
                   Accion = "1";
                   objtamano = $scope.tamanoseleccionado;
                   objprecio = $scope.precioseleccionado;
                   objimpresora = $scope.ListaImpseleccionada;
                   objprecios = $scope.precioseleccionado;//esta pendiente hasta que sepa
                   objselectnoetiquetas = $scope.numeroetiquetaselecionada;
                  //parametros a mandar al store
                   TipoImpresion = objtamano.Id_Etiqueta;
                   SKUinicial = objskuinicial;
                   SKUFinal = objskufinal;
                   ListaTda = "3";
                   ListaPrecios = objprecios.Valor;
                   ListaMay = "4"
                   Impresora = objimpresora.nombreimpresora;
                   PorPieza = "";
                   labels = objtamano.No_Filas;
              if (objcheckpieza == true) { PorPieza = "1"; } else { PorPieza = "0" }
                   ConPrecio = "";
                  if (objcheckprecio == true) { ConPrecio = "1"; } else { ConPrecio = "0" }
              }
               impresion = { Accion, TipoImpresion, SKUinicial, SKUFinal, ListaTda, ListaMay, PorPieza, ConPrecio, Impresora, labels, ListaPrecios };
               datosimpresion.push(impresion);
               var lon = vec.length-1;
               if (i ==  lon) {
                   //llamada a servicio imprimir

                   var etiqueta = datosimpresion;

                   ImprimirService.ImpreTxt(etiqueta)
                       .then(function (response) {
                           if (response.code = 100) {

                               $scope.impri = response.data.Result;
                               $scope.impri = angular.fromJson($scope.impri);
                               $scope.apply;

                           }
                       }, function (err) {

                       });
              return $scope.impri;
              ////
               }

          }//fin del ciclo for
    
asked by Alex 14.06.2018 в 16:49
source

0 answers