防止MatDialog被拖出window

Prevent MatDialog from being dragged out of the window

我目前正在做一个 Angular 项目。我用的是MatDialog from Angular material together with the Angular module of drag and drop。我想防止对话框被拖出屏幕 window。有人知道怎么做吗?

提前致谢。

你不能设置一个与你的屏幕大小相同的框(比如覆盖层)并在里面创建拖拽吗?像这个例子:https://stackblitz.com/angular/omronldbxey?file=src%2Fapp%2Fcdk-drag-drop-boundary-example.ts

您可以为您的 MatDialog 使用所有屏幕尺寸,然后使其可拖动。这 link 可能会有帮助。

您可以将 cdkDragBoundary 设置为 .cdk-overlay-container 具有屏幕大小。

Stackblitz