UI Bootstrap Typeahead $digest 已经在进行中

UI Bootstrap Typeahead $digest already in Progress

在尝试从 $http.get

中填充数据时,Got $digest 已经在进行中

这是我的代码

JSON 结果:

[
  {
    "id": 14,
    "name": "RIAU"
  },
  {
    "id": 21,
    "name": "KEPULAUAN RIAU"
  }
]

控制器:

    $scope.getProvince = function(value) {
      return $http.get('/api/v1/province', {
        params: {
          q: value
        }
      }).then(function(response) {
        return response.data;
    });
   }

HTML

<div class="col-lg-6">
          <!-- Province -->
          <div class="form-group">
            <label>Province</label>
            <input type="text" uib-typeahead="province for province.name in getProvince($viewValue)" placeholder="{{ province }}"
              typeahead-loading="loadingLocations" typeahead-no-results="noResults"
              class="form-control" ng-model="cat.customer.anchor_residence_1.province">
            <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
            <div ng-show="noResults">
              <i class="glyphicon glyphicon-remove"></i> No Results Found
            </div>
          </div>
        </div>

有人知道如何解决这个问题吗?

getProvince函数returns Promise,不是真实数据。您必须将保存数据和列表数据分开。

... in provinces ... ng-keydown=getProvince($viewValue) ... in html

#

问题是混合 angular 摘要循环。

1) 在摘要循环中调用了 getProvince(在 html 中) 2) 在完成 return 承诺之前从服务器获取数据。 3)再次getProvinxe,因为promise不在列表中。所以 "falling in digest cycle in digest cycle"。发生错误。