title: Angular google map close info window on new marker click
body: <p>I am using Angular google map: <a href="https://angular-maps.com/" rel="noreferrer">https://angular-maps.com/</a>.
  Right now as default functionality, it open the info-window defined inside marker.
  And on click of any new marker it remains open old window. I need to close info window on click of another marker.
  This is html code:</p>
  
  <pre><code>&lt;agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom"&gt;
            &lt;agm-marker 
                *ngFor="let m of markers; let i = index"
                (markerClick)="clickedMarker(m.label, infoWindow, i)"
                [latitude]="m.lat"
                [longitude]="m.lng"
                [markerDraggable]="m.draggable"                
                [iconUrl]="m.icon"&gt;
  
              &lt;agm-info-window #infoWindow&gt;
                &lt;strong&gt;{{m.name}}&lt;/strong&gt;&lt;br&gt;
              &lt;/agm-info-window&gt;
  
            &lt;/agm-marker&gt;
          &lt;/agm-map&gt;
  </code></pre>
  
  <p>this is code when marker is clicked:</p>
  
  <pre><code>clickedMarker(label: string, infoWindow, marker, index: number) {
       if( this.infoWindowOpened ===  infoWindow)
        return;
  
      if(this.infoWindowOpened !== null)
      {
       this.infoWindowOpened.close();
      }
      this.infoWindowOpened = infoWindow;
  }
  </code></pre>
  
  <p>It works when the page refresh. But as soon as I refresh markers variable it show this error:</p>
  
  <pre><code>ERROR TypeError: Cannot read property 'then' of undefined
  at InfoWindowManager.close (info-window-manager.js:48)
  at AgmInfoWindow.close (info-window.js:94)
  at SearchComponent.clickedMarker (search.component.ts:188)
  </code></pre>
  
  <p>component code to refresh markers:</p>
  
  <pre><code>this.markers.push({
                name: item.Name,  
                lat: parseFloat(item.latitude.toString()),
                lng: parseFloat(item.longitude.toString()),
                draggable: false,      
                icon:'assets/img/marker.png'
              });
  </code></pre>