首页 文章

错误TS2707:1到2个参数之间的通用类型'MatDialogRef<T,R>' requiers

提问于
浏览
-1

请任何帮助我得到他的错误“错误TS2707:通用类型'MatDialogRef'在1和2参数之间的requiers”当我在我的代码中添加MatDialogRef我尝试了很多解决方案但它对我不起作用

errordialogue.ts:

从'@ angular / core'导入{Component,Inject,Injectable};从'@ angular / material'导入{MatDialogRef,MAT_DIALOG_DATA,MatDialog}; @Component({selector:'dialog-overview-example',templateUrl:'error-dialog.component.html'})export class ErrorDialogComponent {constructor(private dialogRef:MatDialogRef,@ Inject(MAT_DIALOG_DATA)public data:any){} public closeDialog(){this.dialogRef.close(); }}

module.ts;我在imports数组中添加了dialogModule

导入:[BrowserModule,FormsModule,AppRouterModule,HttpModule,HttpClientModule,ReactiveFormsModule,CommonModule,BrowserAnimationsModule,MatDialog,MatDialogModule,MatDialogRef],

2 回答

  • 0

    它错误,因为 MatDialogRef 需要一个通用的签名组件类,这是你的 ErrorDialogComponent

    试试这个

    import {Component, Inject, Injectable} from '@angular/core'; 
    import {MatDialogRef, MAT_DIALOG_DATA, MatDialog} from '@angular/material'; 
    
    @Component({ 
     selector: 'dialog-overview-example',
     templateUrl: 'error-dialog.component.html' 
    }) 
    export class ErrorDialogComponent { 
     constructor(private dialogRef: MatDialogRef<ErrorDialogComponent>, @Inject(MAT_DIALOG_DATA) public 
     data : any) { } 
     public closeDialog(){ this.dialogRef.close(); } 
    }
    
  • 0

    除了'It doesn' t之外没有任何其他工作'我可以给你这个答案:关注docs

相关问题