【问题标题】:Can I somehow detect when Angular cdk overlay changes it's position?我可以以某种方式检测 Angular cdk 覆盖何时改变它的位置吗?
【发布时间】:2021-08-20 17:32:23
【问题描述】:

我有Angular CDK Overlay 用于弹出窗口,当我向下滚动页面时,覆盖向上移动(因为它具有重新定位滚动策略)。

我可以在叠加层向上或向下移动时以某种方式触发事件吗?

【问题讨论】:

    标签: angular overlay angular-cdk


    【解决方案1】:

    当我这样做时,我能够从覆盖参考配置中访问更改。它看起来像这样:

    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
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多