【问题标题】:Google autocomplete in AngularAngular 中的 Google 自动完成功能
【发布时间】:2016-07-01 12:58:16
【问题描述】:

我在 Angular 中遇到 google 自动完成问题。

结构是index.html

我有一页显示在 ng-view - road.html 中。

Road.html

<input id="locationFrom"  type="text" class="form-control"/>

道路控制器:

 app.controller("roadMapController", function () {
 var input = document.getElementById("locationFrom");

        var autocomplete = new google.maps.places.Autocomplete(input);
}

我在控制台中没有错误,输入得到额外的占位符“写入位置...”,但是当我输入时,没有应有的提示。

我做错了什么?

【问题讨论】:

    标签: javascript angularjs google-maps-api-2


    【解决方案1】:

    首先将依赖项添加到您的应用中:

    angular.module('myApp', ['google.places']);
    

    之后

    var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-33.8902, 151.1759),
    new google.maps.LatLng(-33.8474, 151.2631));
    
    var input = document.getElementById('locationFrom');
    var options = {
      bounds: defaultBounds,
      types: ['establishment']
    };
    
    autocomplete = new google.maps.places.Autocomplete(input, options);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多