我使用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
錯誤消息應該更清楚 –