在同一个View AngularJS

时间:2016-08-23 01:18:30

标签: angularjs sqlite

首先抱歉我的英语不好。我正在开发一个能够学习的应用程序,并将所有内容放在控制器,所有查询和所有内容上。但后来我决定将它传递给服务(vi是这样做的权利),只有当我查询我的搜索服务时才停止工作。

在模板中,我列出了所有已注册的类别,并且它有一个输入,这使得搜索DB中的所有已注册的机构。我希望当你进行搜索时,列表只需更新一个新的,只列出此搜索的结果。

当我尝试进行搜索时,会出现以下错误:

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

所有这些都与此模板代码和搜索相关:

Service.js



app.service('Market', function($cordovaSQLite, DBA) {
  var self = this;
  
  self.allCategories = function() {
    return DBA.query("SELECT id, category_name FROM tblCategories")
      .then(function(result){
        return DBA.getAll(result);
    });
  }
  
  self.searchAll = 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 = '';

  $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>
&#13;
&#13;
&#13;

0 个答案:

没有答案