Angularjs Google Autocomplete在angular指令中不适用于mobile safari
我有一个angular指令,用于侦听google place“place_changed”事件。该代码在桌面浏览器中运行良好 但是,它在iOS7中的mobilesafari上不起作用(还没有测试旧版本)。点击一个位置似乎不会触发place_changed事件,输入字段也不会填充位置值 还有什么我应该触发的事件吗Angularjs Google Autocomplete在angular指令中不适用于mobile safari,angularjs,google-maps,safari,angularjs-directive,google-places-api,Angularjs,Google Maps,Safari,Angularjs Directive,Google Places Api,我有一个angular指令,用于侦听google place“place_changed”事件。该代码在桌面浏览器中运行良好 但是,它在iOS7中的mobilesafari上不起作用(还没有测试旧版本)。点击一个位置似乎不会触发place_changed事件,输入字段也不会填充位置值 还有什么我应该触发的事件吗 angular.module('app').directive('googlePlace', function (Location) { return { res
angular.module('app').directive('googlePlace', function (Location) {
return {
restrict: 'A',
require: 'ngModel',
link: function ($scope, element, attributes, model) {
var autocomplete = new google.maps.places.Autocomplete(element[0], {types: ['(cities)']});
google.maps.event.addListener(autocomplete, 'place_changed', function () {
if (autocomplete.getPlace()){
var googlePlace = autocomplete.getPlace();
$scope.googlePlace = googlePlace;
Location.setGooglePlace(googlePlace);
var location = googlePlace.address_components[0].long_name + ', ';
if (googlePlace.address_components.length === 2) {
location = location + googlePlace.address_components[1].long_name;
} else if (googlePlace.address_components.length === 3) {
location = location + googlePlace.address_components[2].long_name;
} else if (googlePlace.address_components[3].short_name === 'US') {
location = location + googlePlace.address_components[2].short_name;
} else {
location = location + googlePlace.address_components[3].long_name;
}
$scope.displayLocation = location;
$scope.$apply(function () {
setTimeout(function(){
model.$setViewValue($scope.displayLocation);
model.$setValidity(element.name, true);
element.val($scope.displayLocation);
}, 100);
});
} else {
$scope.googlePlace = null;
$scope.displayLocation = null;
model.$setViewValue($scope.displayLocation);
model.$setValidity(element.name, true);
element.val($scope.displayLocation);
}
});
element.on('blur', function () {
setTimeout(function(){
if (attributes.required && !$scope.googlePlace){
model.$setValidity(element.name, false);
} else if (element.val() && !$scope.googlePlace){
model.$setValidity(element.name, false);
} else if (!element.val()){
Location.setGooglePlace(null);
model.$setValidity(element.name, true);
} else{
model.$setViewValue($scope.displayLocation);
model.$setValidity(element.name, true);
element.val($scope.displayLocation);
}
}, 300); // this seems to matter even though 0
});
element.on('keypress', function (e) {
$scope.googlePlace = null;
Location.setGooglePlace(null);
if (e.which === 13) {
google.maps.event.trigger(autocomplete, 'place_changed');
}
});
}
};
});
我也有同样的问题。。你以某种方式解决了吗?谢谢。这是一段时间以前的事了-我想我必须禁用该指令的fastclick。Def。值得一看。safari-新IE!