InvalidValueError: not an instance of HTMLInputElement

前端 未结 8 1662
刺人心
刺人心 2020-12-09 08:23

FYI, I\'m not a JavaScript Ninja but felt like I\'ll become one when I did a lot of things based on Google Maps recently.

I implemented a map. User can search for go

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 09:03

    I had the same problem in Angular2. My solution is to move the initialisation of Google Maps to a function that fires when a user focus in the autocomplete input field. Not the most beautiful solution, but it works.

    Code:

    private autocomplete_init: boolean: false;
    
    autocompleteFocus() {
     this.autocomplete_init = true;
     if (!this.autocomplete_init) {
      this._autocomplete = new google.maps.places.Autocomplete(document.getElementById("search_address"), {
      componentRestrictions: {'country': 'dk'}
      }
    }
    

    HTML:

    
    

提交回复
热议问题