我使用angularjs版本1.13.X.In我的应用程序有一个谷歌地方自动完成搜索框作为指令。当加载页面错误显示在控制台中,但搜索框工作正常。谷歌地方自动完成显示错误控制台在angularjs?
InvalidValueError: setComponentRestrictions: in property country: not a string; and not an Array
我的指令代码
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);
});
});
}
};
}
]);
如何解决这个问题?请帮助我,并提前感谢
感谢它的工作,我删除了componentRestrictions:{} –
这是行得通的。谢谢 – Moppo
错误消息应该更清楚 –