diff --git a/index.html b/index.html index a5f9bbf..8db23a0 100644 --- a/index.html +++ b/index.html @@ -43,7 +43,10 @@ templateUrl: 'src/views/modal-busqueda-productos.html', controller: 'modalBusquedaProductosCtrl', size: 'lg', - resolve: {idLista : function() { return -1; }, cotizacion: 1} + resolve: { + idLista : function() { return -1; }, + cotizacion: function() { return 1;} + } } ); diff --git a/src/js/controller.js b/src/js/controller.js index eacf488..bf04b81 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -29,35 +29,23 @@ angular.module('focaBusquedaProductos') if(idLista > 0) { focaBusquedaProductosService .getProductosByIdLista(idLista, $scope.filters) - .then( - function(res) { - for(var i = 0; i < res.data.length; i++) { - res.data[i].precio = res.data[i].precio / cotizacion; - } - $scope.searchLoading = false; - $scope.primerBusqueda = true; - $scope.productos = res.data; - $scope.search(); - primera(); - } - ); + .then(llenarDatos); } else if(idLista === -1) { - focaBusquedaProductosService.getProductos().then( - function(res) { - for(var i = 0; i < res.data.length; i++) { - res.data[i].precio = res.data[i].precio / cotizacion; - } - $scope.searchLoading = false; - $scope.primerBusqueda = true; - $scope.productos = res.data; - $scope.search(); - primera(); - } - ); + focaBusquedaProductosService.getProductos() + .then(llenarDatos); } } }; - + function llenarDatos(res) { + for(var i = 0; i < res.data.length; i++) { + res.data[i].precio = res.data[i].precio / cotizacion; + } + $scope.searchLoading = false; + $scope.primerBusqueda = true; + $scope.productos = res.data; + $scope.search(); + primera(); + } $scope.search = function() { if($scope.productos.length > 0) { $scope.filteredProductos = $filter('filter')(