View results from a search in the same View Angularjs

Asked

Viewed 182 times

0

I’m developing an app to be able to study and, I was assembling everything in the controller, all the queries and everything. Only then I decided to pass everything to a service(I saw that it is correct to do so), only when I passed the queries to a service my search simply stopped working.

In the template I list all registered categories and it has an input, which searches all registered establishments in DB. I would like when the user does a search, the list simply update with a new one, only listing the results of that search.

When I try to make a search, the following error appears:

Object {message: "sqlite3_bind_null failure: bind or column index out of range", code: 0}

And so is all the code related to this template and the search:

Service.js

.service('Market', function($cordovaSQLite, DBA) {
  var self = this;
  
  // Listando todas as categorias
  self.allCategories = function() {
    return DBA.query("SELECT id, category_name FROM tblCategories")
      .then(function(result){
        return DBA.getAll(result);
    });
  }
  
  // Buscar por estabelecimentos
  self.searchPlace = function(nameSearch) {
    var parameters = [nameSearch];
    
    return DBA.query("SELECT id, place_name FROM tblPlaces WHERE place_name LIKE '%(?)%'", parameters)
      .then(function(result) {
        return DBA.getAll(result);
    });
  }
  
  return self;
})

Controller.js

app.controller('CategoriesCtrl', function($scope, Market) {
  $scope.categories = [];
  $scope.categories = null;
  $scope.items = [];
  $scope.items = null;
  
  var nameSearch = '';
  $scope.searchkey = '';

  // Função de clique onde pega o resultado do input e faz a busca
  $scope.myClick = function (search) {
    nameSearch = search;
    console.log(nameSearch);
    
    $scope.searchResult = function(nameSearch) {
      Market.searchAll(nameSearch).then(function(items) {
        $scope.items = items;
        console.log(items);
      });
    }
    
    $scope.searchResult();
  };
  
  $scope.listAllCategories = function() {
    Market.allCategories().then(function(categories) {
      $scope.categories = categories;
    });
  }
  
  $scope.listAllCategories();
})

Categories.html

<div class="bar bar-header item-input-inset">
  <label class="item-input-wrapper">
    <i class="icon ion-ios-search placeholder-icon"></i>
    <input type="text" placeholder="Search" name="key" autocorrect="off" ng-model="searchkey">
  </label>
  <button class="button" ng-click="myClick(searchkey)">Buscar</button>
</div>
<ion-list>
  <ion-item ng-repeat="category in categories">{{category.category_name}}</ion-item>
</ion-list>

1 answer

0

You are calling . then in controller and service, try changing the service to just this:

self.allCategories = function() {
   return DBA.query("SELECT id, category_name FROM tblCategories");
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.