使用Angular Material V17和遗留组件的
具体
import { MatIconModule } from '@angular/material/icon';
@NgModule({
imports: [MatIconModule],
...
})
export class AppModule { }
import { MdDialog, MdDialogRef, MD_DIALOG_DATA } from '@angular/material';
代码示例:
import { Component, Inject } from '@angular/core';
import { MdDialog, MdDialogRef, MD_DIALOG_DATA } from '@angular/material';
@Component({
selector: 'app-legacy-component-example',
templateUrl: './legacy-component-example.component.html',
styleUrls: ['./legacy-component-example.component.css']
})
export class LegacyComponentExampleComponent {
constructor(public dialog: MdDialog) { }
openDialog() {
let dialogRef = this.dialog.open(LegacyComponentExampleDialog, {
data: { name: 'Angular Material V17 and legacy-component' }
});
}
}
@Component({
selector: 'app-legacy-component-example-dialog',
templateUrl: './legacy-component-example-dialog.component.html',
})
export class LegacyComponentExampleDialog {
constructor(
public dialogRef: MdDialogRef,
@Inject(MD_DIALOG_DATA) public data: any) { }
}
在上面的代码示例中,我们在组件中引入了 MdDialog 并在 openDialog 方法中打开了遗留组件的对话框。同时,我们也实现了一个简单的对话框组件 LegacyComponentExampleDialog,它将在打开时显示在屏幕上。