javascript - Angular : google autocomplete works on pc, 但在移动设备上点击不会加载建议

标签 javascript angularjs autocomplete

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

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

简而言之:我点击了谷歌的自动完成建议,它在移动设备上不起作用,但在 PC 上工作得很好。

但是:我没有使用 cordova,只是使用 Nodejs 和响应能力来实现简单的 Angular 。我确实启用了 FastClick,但禁用并没有解决问题......

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

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

在 View 中:

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;

最佳答案

好的 - 不仅注释掉代码:

/*
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>
-->

看来问题已经解决了!

关于javascript - Angular : google autocomplete works on pc, 但在移动设备上点击不会加载建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553113/

相关文章:

javascript - IE 中的 AngularJS 错误与风格 vs ng 风格

python - 在 vim 和 python 中使用 ycm,如何在例如使用时保留文档字符串预览详细参数?

autocomplete - 是否有任何适用于 Mac 的文本编辑器可以配置为具有或已经具有 Lua 自动完成功能?

javascript - 如何使动态和静态内容居中?

javascript - 在 div 中隐藏/显示 swf?

javascript - 如何在一段时间后取消 RXJS 订阅

javascript - 将 Algolia Instantsearch.js 与 Autocomplete.js 同步

javascript - jQuery, nextUntil(), 如果元素不是段落

angularjs - 在 yeoman/angular grunt build 中未更新对字体(font-awesome)资源的引用

json - 如何在以数字为键的 JSON 数据上使用 ng-repeat?