【问题标题】:Meteor and Google Place Autocomplete - InvalidValueError: not an instance of HTMLInputElementMeteor 和 Google Place 自动完成 - InvalidValueError:不是 HTMLInputElement 的实例
【发布时间】:2018-04-16 21:17:26
【问题描述】:

我希望在我的 Meteor 应用输入之一上使用 Google Place Autocomplete。

当我初始化一个会话时,我有一个 InvalidValueError: not an instance of HTMLInputElement,但是当我刷新页面一次时,自动完成功能很好。

我需要对我的代码进行哪些更改才能使自动完成功能在第一次会话中正常工作?

我的代码:

if (Meteor.isClient) {
    window.onload = function() {
    var autocomplete = new google.maps.places.Autocomplete(
      (document.getElementById('autocomplete')),{types:['geocode']}
    );
    google.maps.event.addListener(autocomplete,'place_changed',function(){
      var place = autocomplete.getPlace();
    });
  };
}

感谢您的帮助。

【问题讨论】:

    标签: html meteor autocomplete


    【解决方案1】:

    在输入元素的焦点上调用下面的代码。

     var autocomplete = new google.maps.places.Autocomplete(
      (document.getElementById('autocomplete')),{types:['geocode']}
    );
    

    【讨论】:

      【解决方案2】:

      您应该尝试使用模板实例:

      Template.autocomplete.onRendered(function() {
          // Your autocomplete function
          // var autocomplete = ...
      });
      

      在本例中,我的模板名称是“自动完成”。

      【讨论】:

        猜你喜欢
        • 2017-11-25
        • 1970-01-01
        • 2016-03-07
        • 2019-07-17
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多