0

我试图在我的项目中复制这个 Angular Material 组件示例:https ://material.angular.io/components/dialog/examples 相反我收到此错误:[错误:无法解析 MatDialog 的所有参数:(?,? , ?, ?, ?, ?, ?)][1]

我在下面粘贴了我的代码,非常简单:TS 文件:

import { Component, OnInit } from '@angular/core';
    import { MatDialog } from '@angular/material/dialog';

    @Component({
      selector: 'lib-custom-dialog',
      templateUrl: './custom-dialog.component.html',
      styleUrls: ['./custom-dialog.component.scss']
    })
    export class CustomDialogComponent implements OnInit {
      ngOnInit() {}

      constructor(public dialog: MatDialog) {}
      openDialog() {
        console.log("test");
        const dialogRef = this.dialog.open(CustomDialogWindow);

        dialogRef.afterClosed().subscribe(result => {
          console.log('Dialog result: ${result}');
        });
      }
    }

    @Component({
      selector: 'custom-dialog-window',
      templateUrl: 'custom-dialog-window.html'
    })
    export class CustomDialogWindow {}

和 module.ts 文件:

import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { CustomDialogComponent } from './custom-dialog/custom-dialog.component';
    import { CustomDialogWindow } from './custom-dialog/custom-dialog.component';
    import { MatDialogModule } from '@angular/material/dialog';
    import { MatDialog } from '@angular/material/dialog';
    import { MatDialogRef } from '@angular/material/dialog';


    @NgModule({
      declarations: [
        CustomDialogComponent,
        CustomDialogWindow,
      ],
      imports: [
        CommonModule,
      ],
      exports: [
        CustomDialogComponent,
        CustomDialogWindow,
        MatDialogModule,
        MatDialog,
        MatDialogRef,
      ],
      providers:[
        MatDialogModule,
        MatDialog,
      ]
    })
    export class CustomDialogModule { }

我正在使用 angular 12.0.3 如果有人有任何想法,他们将不胜感激。该组件在一个故事书项目中实现。[1]:https ://i.stack.imgur.com/Lg5F1.png

4

0 回答 0