1

I am retrive the passing value to MAT_DIALOG_DATA any one help me?

spec.ts:

 test('should check component data', async () => {
    const { fixture } = await render(PrintPopupComponent, {
      detectChanges: true,
      imports: [
        MatDialogModule,
        BrowserAnimationsModule.withConfig({ disableAnimations: true }),
      ],
      providers: [
        {
          provide: MatDialogRef,
          useValue: {},
        },
        {
          provide: MAT_DIALOG_DATA,
          useValue: {
            data: { lastName: 'cc' },
          },
        },
      ],
    });
    const component = fixture.componentInstance;
    console.log(component.data.lastName); //undefined;
//expecting 'cc'
  });
});

ts file:

import { Component, Inject, ChangeDetectionStrategy } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
export interface DialogData {
  lastName?: string;
  firstName?: string;
  patientId?: string;
  deviceModel?: string;
  deviceSerial?: string;
  clinicName?: string;
  showHeader?: boolean;
  showFooter?: boolean;
  pageContent?: any;
  currentDocument: string;
  date?: Date;
  pageNumber?: number;
}

@Component({
  selector: 'hf-workspace-print-popup',
  templateUrl: './print-popup.component.html',
  styleUrls: ['./print-popup.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class PrintPopupComponent {
  debugElement: any;
  constructor(
    @Inject(MAT_DIALOG_DATA) public data: DialogData,
    public dialogRef: MatDialogRef<PrintPopupComponent>
  ) {}

  print(): void {
    window.print();
  }

  closeModal(): void {
    this.dialogRef.close();
  }
}
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

0 Answers0