From 6f8c450dc93926f554ae0eb581d9ba234de49364 Mon Sep 17 00:00:00 2001 From: mpuebla Date: Fri, 7 Jun 2019 16:12:57 -0300 Subject: [PATCH] Arreglo cuando el id de lista es nulo. --- src/js/controller.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index e000696..e9a1162 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -31,15 +31,14 @@ angular.module('focaBusquedaProductos') $scope.busquedaPress = function (key) { if (key === 13) { $scope.searchLoading = true; - if (parametroProducto.idLista > 0) { - focaBusquedaProductosService - .getProductosByIdLista(parametroProducto.idLista, $scope.filters) - .then(function (data) { - llenarDatos(data); - focaBusquedaProductosService.getProductos() - .then(fillAllProductos); - }); - } + focaBusquedaProductosService + .getProductosByIdLista(parseInt(parametroProducto.idLista), $scope.filters) + .then(function (data) { + llenarDatos(data); + focaBusquedaProductosService.getProductos() + .then(fillAllProductos); + }) + .catch(function (e) { console.log(e) }); } }; function llenarDatos(res) { @@ -54,7 +53,7 @@ angular.module('focaBusquedaProductos') }; function fillAllProductos(res) { for (var i = 0; i < res.data.length; i++) { - var producto = $scope.listaProductos.filter(function(producto) { + var producto = $scope.listaProductos.filter(function (producto) { return producto.id == res.data[i].id; })[0]; @@ -74,7 +73,7 @@ angular.module('focaBusquedaProductos') primera(); }; $scope.search = function (pressed) { - if ($scope.listaProductos.length > 0) { + if ($scope.listaProductos.length > 0 || $scope.todosProductos.length > 0) { $scope.filteredProductos = $filter('filter')( ($scope.useAllProducts ? $scope.todosProductos : $scope.listaProductos), { $: $scope.filters } -- 1.9.1