我想为overlay.position().flexibleConnectedTo() 配置一个覆盖,因为connectedTo() 已根据official docs 被弃用.
否则有 quesstion对 connectedTo() 有一个很好的回答
这是我的代码
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);
但收到此错误:
“ConnectedToFlexibleConnectedPositionStrategy:至少需要一个位置。在 FlexibleConnectedPositionStrategy.push”
最佳答案
对于那些因为缺乏 this.getPositions()
的实现而坚持接受的答案的好奇者,这是复制粘贴的快速示例:
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
关于 Angular CDK :Getting error for FlexibleConnectedPositionStrategy in Overlay config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59612621/