Home > OS >  Expected expression at generic component
Expected expression at generic component

Time:11-09

I am using material dialog in a component, when establishing a reference to it, the IDE shows me the error "SyntaxError: Expression expected". What is the reason for this?

onDeleteClick(id: number): void {
    const data = this.getSomeData(id);
    const config: MatDialogConfig<ConfirmDeleteDialogConfig<SomeDTO>> = {
      data: {
        data,
        title: 'Sample text'
      }
    };

    if (data) {
      const dialogRef = this.dialog.open(ConfirmDeleteDialogComponent<SomeDTO>, config);
                                                                            //^ SyntaxError: Expression expected
      dialogRef
        .afterClosed()
        .pipe(...)
        .subscribe();
    }
  }

Class, config and dto:

export class ConfirmDeleteDialogComponent<T> {
  constructor(
    public dialogRef: MatDialogRef<ConfirmDeleteDialogComponent<T>>,
    @Inject(MAT_DIALOG_DATA) public data: T
  ) {}

}

export interface ConfirmDeleteDialogConfig<T> {
  data: T;
  title: string;
  text?: string;
}

export interface SomeDTO{ 
    name: string;
    id?: number;
}

CodePudding user response:

You're providing the type ConfirmDeleteDialogComponent<SomeDTO>.

Remove the generic to provide the class

const dialogRef = this.dialog.open(ConfirmDeleteDialogComponent, config);
  • Related