【问题标题】:angular: google autocomplete works on pc, but tapping on mobile doesn't load the suggestion角度:谷歌自动完成在电脑上工作,但在移动设备上点击不会加载建议
【发布时间】:2017-01-25 23:01:24
【问题描述】:

我实际上遇到了同样的问题:

can't tap on item in google autocomplete list on mobile

简而言之:我点了 google 的自动补全建议,它在移动设备上不起作用,而在 PC 上运行正常。

但是:我没有使用 cordova,只是使用 nodejs 和响应能力的普通角度。我确实启用了 FastClick,但禁用并没有解决问题....

编辑:这是我的完整性代码: 标记(玉):

div
  input(type="text" id="fulladdress" name="fulladdress" ng-model="location" class="form-control text-field" placeholder="Start typing...")

在视图中:

form.row(ng-show="vm.isLogged" name="vm.form")
  h2.order-title Delivery address
  label(for="address") Address
  google-places(location="vm.address")

js:

'use strict';

GooglePlacesDirective.$inject = ['$animate', 'Zipcode'];

function GooglePlacesDirective($animate, Zipcode) {
    return {
        scope: {location:'='},
        restrict: 'E',
        replace: true,
        template: require('./google-places.html'),
        link: link
    };

    function link(scope, element) {
        scope.codeNotServed = false;
        var options = {
          componentRestrictions: {country: "us"}
        };
        var autocomplete = new google.maps.places.Autocomplete($("#fulladdress")[0], options);
        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            scope.codeNotServed = false;
            var place = autocomplete.getPlace();
            var parts = place.address_components;
            //do things with the parts; I've also tried doing nothing with the parts, but it didn't work either
         });
    }
}

module.exports = GooglePlacesDirective;

【问题讨论】:

    标签: javascript angularjs autocomplete


    【解决方案1】:

    好的 - 不仅注释掉代码:

    /*
    if ('addEventListener' in document) {
        console.log("Attaching FastClick event listener");
        document.addEventListener('DOMContentLoaded', function() {
            FastClick.attach(document.body);
        }, false);
    }
    */
    

    还有库的实际加载:

    <!--
    <script src="/bower_components/fastclick/lib/fastclick.js"></script>
    -->
    

    看来问题已经解决了!

    【讨论】:

      猜你喜欢
      • 2012-04-15
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      相关资源
      最近更新 更多