Can I somehow detect when Angular cdk overlay changes it's position?

Viewed 684

I have Angular CDK Overlay for popovers, when I scroll page down, overlay moves up (because it has reposition scroll strategie).

Can I somehow trigger an event when the overlay moves up or down?

1 Answers

When I did this, I was able to access the change from the overlay reference config. It looked something like this:

export class MyClass {
  constructor(private overlayRef: OverlayRef) {}

  ngOnInit() {
    const config = this.overlayRef.getConfig();
    // positionChanges is private so this bypasses the error
    const changes = (config.positionStrategy as any)['positionChanges']

    changes.subscribe((change: ConnectedOverlayPositionChange) => {
      // Do something when the position changes
    });
  }
}
Related