我正在使用angularjs版本1.13.X.在我的应用程序中有一个谷歌放置自动完成搜索框作为指令.当加载页面后显示在控制台中的错误,但搜索框工作正常.
InvalidValueError: setComponentRestrictions: in property country: not a string; and not an Array
Run Code Online (Sandbox Code Playgroud)
我的指令代码
routerApp.directive('googleplace', ['$state', function ($state) {
return {
require: 'ngModel',
link: function (scope, element, attrs, model) {
var options = {
types: [],
componentRestrictions: {}
};
scope.gPlace = new google.maps.places.Autocomplete(element[0], options);
google.maps.event.addListener(scope.gPlace, 'place_changed', function (e) {
scope.$apply(function () {
model.$setViewValue(element.val());
var countrycode = "na";
var latitude = 0;
var longitude = 0;
scope.secondplacebox = scope.chosenPlace;
for (var i = 0; i < scope.gPlace.getPlace().address_components.length; i++) {
if (scope.gPlace.getPlace().address_components[i].types[0] == 'country') {
countrycode = scope.gPlace.getPlace().address_components[i].short_name;
}
}
latitude = scope.gPlace.getPlace().geometry.location.lat().toFixed(6);
longitude = scope.gPlace.getPlace().geometry.location.lng().toFixed(6);
//$state.go('home');
scope.Fn_setCookieData(latitude, longitude, countrycode);
});
});
}
};
}
]);
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?请帮助我,并提前感谢
Nik*_*hri 11
我看options是有componentRestrictions,它并不局限于某一特定国家.像国家限制一样componentRestrictions: {country: 'fr'}可以解决问题.替换fr您的国家/地区要求.如果您不需要对国家/地区的限制,只需避免在选项中使用它.
希望这对你有所帮助!
| 归档时间: |
|
| 查看次数: |
3288 次 |
| 最近记录: |