我正在尝试向 Angular Bootstrap Typeahead 传递一个承诺,但我总是遇到以下错误:TypeError: Cannot read property 'length' of undefined
工厂:
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 一切正常。问题在于 Bootstrap-UI 0.6.0 (bootstrap3_bis2)。 https://github.com/angular-ui/bootstrap/tree/bootstrap3_bis2