【发布时间】:2017-12-12 22:53:23
【问题描述】:
我正在使用 angular 5 和 angular material(最新版本),我正在尝试从页面打开一个对话框。当我单击触发打开的按钮时,整个网站都被置于空白背景中,就像对话框将其内容重叠并全部隐藏一样。
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
@Component({
moduleId: module.id,
selector: 'app-dialog',
templateUrl: 'dialog.component.html',
styleUrls: ['dialog.component.scss']
})
export class DialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<DialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
onNoClick(): void {
this.dialogRef.close();
}
ngOnInit() {
}
}
这就是打开对话框的方法。
onSubmit() {
const dialogRef = this.dialog.open(DialogComponent, {
width: '250px',
data: { name: 'Juan Manuel', animal: 'Perro' }
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
console.log(result);
});
}
更新: 我已经看到,在呈现对话框后,一个类被添加到我的 html 标记中。 .cdk-global-scrollblock我不知道为什么那个类被添加到我的html标签中。
.cdk-global-scrollblock {
position: fixed;
width: 100%;
overflow-y: scroll;
}
这是导致我的错误的原因。有人知道为什么我的 html 标签上有那个类吗?
【问题讨论】:
-
检查控制台,可能会触发一些异常,可能是组件初始化问题。
-
nop,控制台上没有错误对话框打开正常,但我的所有网站都是灰色和空白
-
上面的类是在哪里添加的。你能用 plunker 复制吗?
-
我不能使用 plunker,但我已经按照官方 Angular Material 网站的教程进行操作。并且对话框容器在路由器插座内,不知道这是否有帮助
-
你能告诉我们你的
app.module.ts吗?
标签: angular material-design angular-material