Commit e9c0055cae5e7433bccadeee1983d6ce2a7ed4b7
1 parent
8ede82af14
Exists in
master
and in
1 other branch
Array de promesas
Showing
1 changed file
with
12 additions
and
9 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -51,22 +51,25 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 51 | 51 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 52 | 52 | } |
| 53 | 53 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 54 | - crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | |
| 55 | - var monedaPorDefecto = res.data[0]; | |
| 54 | + //Trabajo con el proveedor YPF, por eso uso siempre la primera | |
| 55 | + | |
| 56 | + var promiseMoneda = crearNotaPedidoService.getCotizacionByIdMoneda(1); | |
| 57 | + var promiseProveedor = crearNotaPedidoService.getProveedorById(1); | |
| 58 | + | |
| 59 | + Promise.all([promiseMoneda, promiseProveedor]).then(function(res) { | |
| 60 | + var monedaPorDefecto = res[0].data[0]; | |
| 56 | 61 | $scope.notaPedido.cotizacion = Object.assign( |
| 57 | 62 | {moneda: monedaPorDefecto}, |
| 58 | 63 | monedaPorDefecto.cotizaciones[0] |
| 59 | - ); | |
| 60 | - $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | |
| 61 | - $timeout(function() {getLSNotaPedido();}); | |
| 62 | - }); | |
| 63 | - //Trabajo con el proveedor YPF, por eso uso siempre la primera | |
| 64 | - crearNotaPedidoService.getProveedorById(1).then(function (res){ | |
| 65 | - var proveedorPorDefecto = res.data[0]; | |
| 64 | + ); | |
| 65 | + $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | |
| 66 | + var proveedorPorDefecto = res[1].data[0]; | |
| 66 | 67 | $scope.notaPedido.proveedor = Object.assign( |
| 67 | 68 | {proveedor: proveedorPorDefecto} |
| 68 | 69 | ); |
| 69 | 70 | $scope.inicial.proveedor = $scope.notaPedido.proveedor; |
| 71 | + | |
| 72 | + $timeout(function() {getLSNotaPedido();}); | |
| 70 | 73 | }); |
| 71 | 74 | |
| 72 | 75 | init(); |