我正在尝试将对话框与我的应用程序合并,但我分配的任何属性,例如 hasBackdrop = true (我知道这是默认值),都不会改变行为。当对话框打开时,我可以单击 UI 中的任意位置并与其交互,同时对话框保持打开状态。因此,我能够进行 API 调用,甚至打开多个对话框。
这是我的 ts 文件和 html 文件的一些片段。
export class MenuItemsComponent{
constructor(private dialog: MatDialog){}
@Input() menuItemsPerCategory: MenuItemModel[] = [];
openDialog():void{
const dialogConfig = new MatDialogConfig();
dialogConfig.hasBackdrop = true;
const dialogRef = this.dialog.open(MenuItemDialogContainer, dialogConfig);
}
<div (click)="openDialog()">
{{ menuItemsPerCategory[0].name }}
</div>
}
此外,在应用程序模块文件中,我尝试在提供者数组下分配此对象,没有任何明显的更改。
{ provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false} }
这是我的 package.json 文件
{
"name": "example-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^16.1.1",
"@angular/cdk": "16.1.6",
"@angular/common": "^16.1.1",
"@angular/compiler": "^16.1.1",
"@angular/core": "^16.1.1",
"@angular/forms": "^16.1.1",
"@angular/material": "16.1.6",
"@angular/material-moment-adapter": "16.1.6",
"@angular/platform-browser": "^16.1.1",
"@angular/platform-browser-dynamic": "^16.1.1",
"@angular/router": "^16.1.1",
"moment": "^2.18.1",
"rxjs": "~7.4.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.1.0",
"@angular/cli": "^16.1.0",
"@angular/compiler-cli": "^16.1.1",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.10.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~5.0.3"
}
}
我什至访问了 Material 的官方文档页面(https://material.angular.io/components/dialog/examples),单击了 StackBlitz 的一个示例,并在 Visual Studio 代码中进行了直接复制和粘贴工作。不幸的是,我的功能并没有模仿我在 StackBlitz 上看到的功能。我在复制和粘贴作业中看到的是,当我单击它时,对话框保持打开状态,并且我能够打开多个对话框。
import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
@Component({
selector: 'app-root',
template: `<button mat-button (click)="openDialog()">Launch dialog</button>`,
//styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(public dialog: MatDialog) {}
openDialog() {
this.dialog.open(DialogElementsExampleDialog);
}
}
@Component({
selector: 'dialog-elements-example-dialog',
template: `<h1 mat-dialog-title>Dialog with elements</h1>
<div mat-dialog-content>This dialog showcases the title, close, content and actions elements.</div>
<div mat-dialog-actions>
<button mat-button mat-dialog-close>Close</button>
</div>
`
})
export class DialogElementsExampleDialog {}