【问题标题】:Angular material Dragable dialogbox is not working角材料可拖动对话框不起作用
【发布时间】:2023-03-10 15:31:01
【问题描述】:

我有一个可拖动的对话框,它不起作用。 但我在另一个项目中有类似的工作代码。

我的主要代码:

<div cdkDrag cdkDragRootElement=".cdk-overlay-pane" >
    <h2 mat-dialog-title cdkDragHandle> Justin Wu</h2>
</div>
<label>I am a {{ position}}</label>
<div>
    <button class="close" mat-button (click)="closeDialog()">Close</button> 
    <button class="save" mat-button  (click)="closeDialog()">Save</button>
</div>

您可以从这里找到演示:http://www.justa999.com/angular/#/profile

点击“关于我”按钮后,您会看到它

您可以从 profile.component.ts 调试源代码

我的版本:

{
"@angular-devkit/build-angular": "~0.901.0",
"@angular/cli": "~9.1.0",
"@angular/compiler-cli": "~9.1.0",
"@angular/language-service": "~9.1.0",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.12.62",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"
}

【问题讨论】:

    标签: angular angular-material dialog draggable


    【解决方案1】:

    试试

    <h2 mat-dialog-title cdkDrag cdkDragRootElement=".cdk-overlay-pane" cdkDragHandle> Justin Wu</h2>
    <div mat-dialog-content >
    <label>I am a {{ position}}</label>
    </div>
    <div mat-dialog-actions>
       <button class="close" mat-button (click)="closeDialog()">Close</button> 
       <button class="save" mat-button  (click)="closeDialog()">Save</button>
    </div>
    

    【讨论】:

      【解决方案2】:

      Angular Modal 和 CDK Drag 经常重叠,你可以使用普通的 div 并设置它的 css

      position: absolute;
      left: 50px;
      top: 50px;
      

      所以它显示为模态,cdkdrag 有效。

      【讨论】:

      【解决方案3】:

      我自己解决了这个问题:

      首先,您必须将您的内容添加到

      <mat-dialog-content>
          <label>I am a {{ position}} </label>
      </mat-dialog-content>
      

      其次,你必须在 app.module.ts 中声明你的对话框组件

      @NgModule({
        declarations: [
          ModalContentComponent,   
      

      【讨论】:

        猜你喜欢
        • 2018-11-14
        • 2020-04-24
        • 2022-11-17
        • 1970-01-01
        • 2021-08-18
        • 1970-01-01
        • 2021-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多