我正在尝试使用 jQuery Geocomplete使用我的 AngularJS 应用程序。
我的 html 页面中有这个。
<input id="destination-location-input" type="text" class="form-control"
ng-model="destCtrl.destination" ng-change="destCtrl.locationChanged()"
data-geocomplete="street address" required/>
并在 Controller 中添加此代码。
var myElement = angular.element( document.querySelector('#destination-location-input'));
myElement.geocomplete(
{
appendToParent: true,
onChange: function(name, result) {
var location = result.geometry.location;
},
onNoResult: function(name) {
console.log("Could not find a result for " + name)
}
});
运行我的应用程序时,出现此错误。
TypeError: myElement.geocomplete is not a function
可能是什么问题?
最佳答案
确保在加载此插件之前将 Google Maps API 包含在 Places Library 中,如 here 所述
<script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script src="jquery.geocomplete.js"></script>
关于javascript - AngularJS:不是函数类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49292853/