Angular mapsAPILoader.load()侦听器不是第一次侦听

Angular mapsAPILoader.load()侦听器不是第一次侦听,angular,agm-core,Angular,Agm Core,我正在使用agm/core在angular component中自动完成谷歌地址,我在我的服务模块中添加了以下代码 @NgModule({ imports:[ AgmCoreModule.forRoot({ apiKey: 'testAPiKEY', libraries: ['places'] }),] } 在我的组件的init上,我添加了以下代码 this.mapsAPILoader.load().then(() => { const autocomp

我正在使用
agm/core
在angular component中自动完成谷歌地址,我在我的服务模块中添加了以下代码

@NgModule({
  imports:[ AgmCoreModule.forRoot({
    apiKey: 'testAPiKEY', 
    libraries: ['places']
  }),]
}
在我的组件的init上,我添加了以下代码

this.mapsAPILoader.load().then(() => {  
  const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
            types: ['address']
    });
  this.autoComplete.addListener('place_changed', () => {
    this.zone.run(() => {
      // get the place result
      const place: google.maps.places.PlaceResult = this.autoComplete.getPlace();
    this.form
      .get('locations.address')
      .setValue(place['formatted_address']);
    place.address_components.forEach((placeComponent) => {
      const addressType = placeComponent.types[0];

      if (addressType === 'administrative_area_level_1') {                  
        this.form
          .get('locations.state')
          .setValue(placeComponent['long_name']);
      } else if ( addressType === 'administrative_area_level_2') {                  
        this.form
          .get('locations.city')
          .setValue(placeComponent['long_name']);
      } else if (addressType === 'country') {
        this.form
          .get('locations.country')
          .setValue(placeComponent['long_name']);
      } else if (addressType === 'postal_code') {                  
        this.form
          .get('locations.zip')
          .setValue(placeComponent['long_name']);
      }
    });

    // verify result
    if (place.geometry === undefined || place.geometry === null) {
       return;
    }
    // -------------

   });
  });          
});
但是,在之后选择第一次地址时,它不起作用 当我第二次键入address并选择它时加载该组件。 有什么想法吗