【发布时间】:2017-01-10 05:11:43
【问题描述】:
我正在使用 angularjs 版本 1.13.X。在我的应用程序中有一个 google 地方自动完成搜索框作为指令。加载页面时,控制台中显示以下错误,但搜索框工作正常。
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);
});
});
}
};
}
]);
如何解决这个问题?请帮助我并提前感谢
【问题讨论】:
标签: angularjs