简体   繁体   English

Angular 8 中的可拖动和可调整大小的垫子对话框

[英]draggable and resizeable mat-dialog in Angular 8

looking for a way to be able to make a mat-dialog both draggable and resizeable.寻找一种能够使 mat-dialog 既可拖动又可调整大小的方法。 So far I have the draggable part done already using cdkDrag (DragDropModule).到目前为止,我已经使用 cdkDrag (DragDropModule) 完成了可拖动部分。 I have tried using resize: booth;我试过使用调整大小:展位; in css but it seems as it isn't working well with combined with draggable functionality.在 css 中,但它似乎与可拖动功能结合使用时效果不佳。 Ie if i remove the cdk the resizable works and vice versa.即,如果我删除 cdk 可调整大小的作品,反之亦然。

See code here: https://stackblitz.com/edit/angular-vp8xt7请参阅此处的代码: https://stackblitz.com/edit/angular-vp8xt7

In your StackBlitz , a resize handle appears bottom right of the dialog, hence you're almost there.在您的StackBlitz中,对话框的右下角会出现一个调整大小的句柄,因此您就快到了。 The problem is that mouse events are consumed by the dragging functionality and not handed over to the resizing functionality.问题是鼠标事件被拖动功能消耗,而不是交给调整大小功能。

Adding a cdkDragHandle to the h1 element solves your problem.cdkDragHandle添加到h1元素可以解决您的问题。

<h1 mat-dialog-title cdkDrag cdkDragRootElement=".cdk-overlay-pane" cdkDragHandle>

Shee how it workes on your forked StackBlitz .看看它在你的分叉StackBlitz上是如何工作的。

For resizeable mat dialog component:对于可调整大小的垫子对话框组件:

use css for panel class like this..像这样将 css 用于面板 class ..

.custom-mat-dialog-panel .mat-dialog-container { 
  resize: both;
}

ts file: ts文件:

openDialog() {
    this.dialog.open(HelloComponent,{height:'100px',width:'100px', panelClass: 'custom-mat-dialog-panel'});
}

For draggable mat dialog component:对于可拖动的垫子对话框组件:

<div mat-dialog-title cdkDrag cdkDragRootElement=".cdk-overlay-pane" cdkDragHandle>
 Draggable Title
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM