Skip to content

fix(google-maps): info window not opening if no anchor is passed in #21014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/google-maps/map-info-window/map-info-window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ describe('MapInfoWindow', () => {
expect(addSpy).toHaveBeenCalledWith('zindex_changed', jasmine.any(Function));
subscription.unsubscribe();
});

it('should be able to open an info window without passing in an anchor', () => {
const infoWindowSpy = createInfoWindowSpy({});
createInfoWindowConstructorSpy(infoWindowSpy).and.callThrough();

const fixture = TestBed.createComponent(TestApp);
const infoWindowComponent = fixture.debugElement.query(By.directive(
MapInfoWindow))!.injector.get<MapInfoWindow>(MapInfoWindow);
fixture.detectChanges();

infoWindowComponent.open();
expect(infoWindowSpy.open).toHaveBeenCalledTimes(1);
});

});

@Component({
Expand Down
7 changes: 5 additions & 2 deletions src/google-maps/map-info-window/map-info-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ export class MapInfoWindow implements OnInit, OnDestroy {
this._assertInitialized();
const anchorObject = anchor ? anchor.getAnchor() : undefined;

// Prevent the info window from initializing if trying to reopen on the same anchor.
if (this.infoWindow.get('anchor') !== anchorObject) {
// Prevent the info window from initializing when trying to reopen on the same anchor.
// Note that when the window is opened for the first time, the anchor will always be
// undefined. If that's the case, we have to allow it to open in order to handle the
// case where the window doesn't have an anchor, but is placed at a particular position.
if (this.infoWindow.get('anchor') !== anchorObject || !anchorObject) {
this._elementRef.nativeElement.style.display = '';
this.infoWindow.open(this._googleMap.googleMap, anchorObject);
}
Expand Down