Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular CDK:Getting error for FlexibleConnectedPositionStrategy in Overlay config

I want to configure an overlay for with overlay.position().flexibleConnectedTo() because connectedTo() is deprecated as per the official docs. Otherwise there is a quesstion having a good answer for connectedTo() enter image description here

Here is my Code

    const origin:FlexibleConnectedPositionStrategyOrigin=this.RefElem;
    const overlayConfig = new OverlayConfig();
    overlayConfig.positionStrategy = this.overlay.position().flexibleConnectedTo(origin);
    const overlayRef = this.overlay.create(overlayConfig);
    const userProfilePortal = new ComponentPortal(
      GraphMetaSignalSelectorComponent
    );
    overlayRef.attach(userProfilePortal);

but getting this error: "ConnectedToFlexibleConnectedPositionStrategy: At least one position is required. at FlexibleConnectedPositionStrategy.push"

like image 356
DevLoverUmar Avatar asked Oct 18 '25 21:10

DevLoverUmar


1 Answers

For those curious who stuck with the accepted answer because of the lack of the implementation of this.getPositions(), here's a quick sample for copy-pasting:

const positionStrategy = this.overlay.position()
      .flexibleConnectedTo(origin)
      .withPositions([{
        // here, top-left of the overlay is connected to bottom-left of the origin; 
        // of course, you can change this object or generate it dynamically;
        // moreover, you can specify multiple objects in this array for CDK to find the most suitable option
        originX: 'start',
        originY: 'bottom',
        overlayX: 'start',
        overlayY: 'top'
      } as ConnectedPosition])
      .withPush(false); // or true, if you want to push the overlay into the screen when it doesn't fit
like image 192
Alexey Grinko Avatar answered Oct 22 '25 01:10

Alexey Grinko