ui.bootstrap.typeahead的null引用错误

时间:2014-11-06 17:37:40

标签: angular-ui angular-ui-bootstrap

我从角度ui

添加了这个角度指令的工作页面
        <input type="text" ng-model="vm.test" placeholder="prima selezionare il comune"
               typeahead="address for address in vm.updateQuartieri($viewValue)"
               typeahead-loading="loadingLocations" class="form-control"  />
        <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>

我使用控制器作为语法,updateQuartieri返回一个字符串数组,所有控制器都正常工作。当我开始输入文本框时,我收到此错误

TypeError: Cannot read property 'length' of undefined
    at http://localhost:43638/Scripts/angular-ui/ui-bootstrap-tpls.js:3602:24

寻找来源

var getMatchesAsync = function(inputValue){

var locals = {$viewValue: inputValue};
isLoadingSetter(originalScope, true);
$q.when(parserResult.source(originalScope, locals)).then(function(matches) {

  //it might happen that several async queries were in progress if a user were typing fast
  //but we are interested only in responses that correspond to the current view value
  var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
  if (onCurrentRequest && hasFocus) {
    if (matches.length > 0) {

看起来像是在服务器调用期间发生的错误,因为在我执行调用之前一切正常,并且在服务器调用返回数据之前发生。    我使用角度1.3。    有什么建议? 卢卡

1 个答案:

答案 0 :(得分:0)

是的,我解决了,问题是在typeahead中对控制器的调用是异步的,所以你要调用的方法必须返回一个promise,而不是实际的数据。