DevLoverUmar
DevLoverUmar

Reputation: 14001

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"

Upvotes: 4

Views: 4696

Answers (2)

Alex Grin
Alex Grin

Reputation: 3203

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

Upvotes: 12

DevLoverUmar
DevLoverUmar

Reputation: 14001

It should be like

positionStrategy=this.overlay.position().flexibleConnectedTo(origin)
                 .withPositions(this.getPositions()).withPush(false) 

the function this.getPositions() return an array of positions Note: Answer is based on a comment by @Eliseo which solved my problem

Upvotes: 0

Related Questions