【发布时间】:2017-04-21 11:11:18
【问题描述】:
正如你所知,每次我们输入谷歌地图时,自动完成都会触发,我想为此设置一个延迟功能,例如 250 毫秒,这样给用户更多的输入时间并节省积分。我尝试添加 $timeout,但看起来它对我不起作用。请你帮我看看这个好吗?提前谢谢。 html:
<input name="google_places_ac" type="text" class="google_places_ac input-block-level" ng-model="address" placeholder="Please enter a location" ng-blur="updateMap()"/>
指令:
link: function($scope, elm, attrs) {
$timeout(function(){
var autocomplete = new google.maps.places.Autocomplete($(elm).find(".google_places_ac")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
$scope.address = place.formatted_address;
$scope.location = {
formatted_address: place.formatted_address,
loglat: place.geometry.location
};
$scope.$apply();
//pop up the event and index(if needed)
$scope.$emit('updatemap',$scope.indexposition);
});
},1000);
}
每次我尝试输入搜索输入时,它都会立即弹出搜索结果列表,有什么办法可以延迟吗?所以用户可以输入更多的字符?
【问题讨论】:
标签: angularjs google-maps google-maps-api-3 angularjs-directive