Meteor和Google Place Autocomplete - InvalidValueError:不是HTMLInputElement的实例

时间:2016-02-09 21:49:40

标签: html meteor autocomplete

我希望在我的一个Meteor App Input上使用Google Place Autocomplete。

初始化会话时,我有一个 InvalidValueError:不是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();
    });
  };
}

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

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

我的模板名称是"自动完成"在这个例子中。