2016-09-23 78 views
3

組件谷歌地方自動填充未出現

import Ember from 'ember'; 

export default Ember.TextField.extend({ 
type: 'text', 

didInsertElement: function() { 
    this.$().addClass("form-control"); 
    var autocomplete = new google.maps.places.Autocomplete(
    (document.getElementById('autocomplete')),{types:['geocode']} //trying without jQuery, but still. 
); 
}}); 

模板

{{gp-textfield id="autocomplete"}} 

這使得以

<input id="autocomplete" type="text" class="ember-view ember-text-field form-control" placeholder="Enter a location" autocomplete="off"> 

但儘管如此,我得到:

InvalidValueError: not an instance of HTMLInputElement 

任何幫助將非常感激。

編輯:餘燼2.6

清理代碼位,與無濟於事

didInsertElement: function() { 
    this.$().addClass("form-control"); 
    var element = document.getElementById('autocomplete'); 
    var autocomplete = new google.maps.places.Autocomplete(element); 
} 
+0

不是您的問題的解決方案,但您可以使用類屬性[「classNames」](http://emberjs.com/api/classes/Ember.Component.html#property_classNames)指定類的名稱零件。它會將它們連接到父類的類名稱以及模板中由'class'屬性指定的任何類。 – akst

+0

此外,它可能與問題有關,但不是重寫didInsertElement,而是建議定義一個新方法,但將其定義爲像'Ember.on('didElementInsert',<你的函數>)',它仍然會運行插入但不覆蓋父類中的didInsertElement方法,或者您可以在函數的開頭調用this._super(arguments),但我感覺前者更加整潔。 – akst

+0

有關覆蓋['didInsertElement']的更多信息(https://guides.emberjs.com/v2.6.0/components/the-component-lifecycle/#toc_integrating-with-third-party-libraries-with-code-didinsertelement-代碼),更多關於['Ember.on'](http://emberjs.com/api/classes/Function.html#method_on) – akst

回答

1

使用Chrome的網絡選項卡。

顯然我的API密鑰沒有被授權使用此功能,我必須啓用它。

相關問題