AngularJS 1.2.0引导UI 0.6.0(引导P3_bis2)类型预发

AngularJS 1.2.0引导UI 0.6.0(引导P3_bis2)类型预发,angularjs,angular-ui,angular-ui-bootstrap,angularjs-bootstrap,Angularjs,Angular Ui,Angular Ui Bootstrap,Angularjs Bootstrap,我试图向Angular Bootstrap Typeahead传递一个承诺,但我总是得到一个附带的错误: TypeError:无法读取未定义的属性“length” 工厂: angular.module('app').factory('geoCoding', ['$http', 'geoUtils', function ($http, geoUtils) { var request= function(location){ return $http.get('http://o

我试图向Angular Bootstrap Typeahead传递一个承诺,但我总是得到一个附带的错误: TypeError:无法读取未定义的属性“length”

工厂:

    angular.module('app').factory('geoCoding', ['$http', 'geoUtils', function ($http, geoUtils) {

  var request= function(location){
    return $http.get('http://open.mapquestapi.com/geocoding/v1/address',{params:{location:location}});
  };

  var ret = {};

  ret.locate = function (location) {
    return request(location).then(function (data) {
      if (data  && data.data && data.data.results && data.data.results[0]) {
        var locations = [];
        data.data.results[0].locations.forEach(function (location) {
          locations.push({name: geoUtils.location2String(location), location: location});
        });
        return locations;
      }
    });
  };
  return ret;
}]);
控制器:

$scope.getLocations = function(){
    console.log('scope',$scope.inputLocation);
    return geoCoding.locate($scope.inputLocation);
  }
模板:

        <input type="text" class="form-control oo-focus" placeholder="Search" typeahead="location as location.name for location in getLocations()" typeahead-wait-ms="500" ng-model="inputLocation" />

在旧版本Angular Bootstrap UI 0.5.0中,一切正常。问题在于BootstrapUI 0.6.0(bootstrap3_bis2)。

如果您使用的是AngularJS 1.2.0-rc.2,那么promises(promise self-reference的名称发生了变化,或者类似于这样的想法:)会有问题。我不能告诉你原因,但你可以在这里找到更多信息:

对我来说,wirking解决方案是带有promise.$$v变量的设置。因此,在您的示例中,代码应该是:

$scope.getLocations = function(){
   console.log('scope',$scope.inputLocation);
   var promise = geoCoding.locate($scope.inputLocation);
   promise.$$v = promise;
   return promise;
}

我同意作者(威尔森·杰克逊)的观点,这是一个骇客!无论如何,希望它能对您有所帮助。

如果您使用的是AngularJS 1.2.0-rc.2,则承诺存在问题(更改了承诺自引用的公开–或类似的想法:)。我不能告诉你原因,但你可以在这里找到更多信息:

对我来说,wirking解决方案是带有promise.$$v变量的设置。因此,在您的示例中,代码应该是:

$scope.getLocations = function(){
   console.log('scope',$scope.inputLocation);
   var promise = geoCoding.locate($scope.inputLocation);
   promise.$$v = promise;
   return promise;
}

我同意作者(威尔森·杰克逊)的观点,这是一个骇客!无论如何,希望它能对您有所帮助。

Angular 1.2.0-rc.3已发布,该版本正常:

Angular 1.2.0-rc.3已发布,该版本正常: