首页 > 解决方案 > Angular closing material dialog from dialog's child component throws errors

问题描述

I am closing my dialog from dialog's child component :

Dialog.html :

<ng-container>
    <app-invoice-form  [disabled]="false" [formGroup]="invoiceFormGroup" [hash]="data.hash" [afterPayment]="true">
    </app-invoice-form>
</ng-container>

InvoiceForm.ts :

 constructor(
    public dialogRef: MatDialogRef<InvoiceDialog>
  ) { }

  public goBackToOrder() {
    this.dialogRef.close();
    this.router.navigate(['/cart', this.hash, true]);
  }

When goBackToOrder() fires, everything looks good, dialog closes, router navigates, but then after router navigates i am getting these errors in my console :

ERROR NullInjectorError: R3InjectorError(CartModule)[MatDialogRef -> MatDialogRef -> MatDialogRef -> MatDialogRef]: NullInjectorError: No provider for MatDialogRef!

How to fix this error ?

CartModule imports MatDialogModule.

标签: javascriptangulartypescriptangular-material

解决方案


推荐阅读