【问题标题】:AngularJS Typeahead giving an error about "matches"AngularJS Typeahead 给出关于“匹配”的错误
【发布时间】:2024-05-20 05:55:02
【问题描述】:

我的观点是:

 <input type="text" ng-model="receivingSku" placeholder="Locations loaded via $http" typeahead="sku for sku in getSku($viewValue) | filter:$viewValue" typeahead-on-select="selectedSku()" class="form-control">

我的控制器有:

  $scope.getSku = function(skuValue) {
    ItemService.search(CompanyService.getCompany()._id, skuValue).then(function(response) {
      var skus = response.data.items.map(function(e) {
        return e.sku;
      });
      return skus;
    });
  }

返回的skus 是一个数组,如:['1221','193A2']

当我输入一些东西时,我得到一个错误:

Error: matches is undefined .link/getMatchesAsync/<@http://localhost:3000/lib/angular-bootstrap/ui-bootstrap-tpls.js:3186 zd/e/l.promise.then/A@http://localhost:3000/lib/angular/angular.min.js:93 zd/e/l.promise.then/A@http://localhost:3000/lib/angular/angular.min.js:93 zd/g/<.then/<@http://localhost:3000/lib/angular/angular.min.js:94 Ad/this.$get</h.prototype.$eval@http://localhost:3000/lib/angular/angular.min.js:102 Ad/this.$get</h.prototype.$digest@http://localhost:3000/lib/angular/angular.min.js:100 Ad/this.$get</h.prototype.$apply@http://localhost:3000/lib/angular/angular.min.js:103 pb/h@http://localhost:3000/lib/angular/angular.min.js:126 Yc/c/<@http://localhost:3000/lib/angular/angular.min.js:27 q@http://localhost:3000/lib/angular/angular.min.js:7 Yc/c@http://localhost:3000/lib/angular/angular.min.js:27

然后它对 ItemService 执行 AJAX 请求,结果正确,但错误阻止了预输入功能

【问题讨论】:

  • 返回整个搜索服务以及回调的内部返回。

标签: angularjs bootstrap-typeahead


【解决方案1】:

看来我需要兑现承诺了,唉:

  $scope.getSku = function(skuValue) {
    return ItemService.search(CompanyService.getCompany()._id, skuValue).then(function(response) {
      var skus = response.data.items.map(function(e) {
        return e.sku;
      });
      return skus;
    });
  }

【讨论】: