0

I need to show data in JSON view inside MatDialog. I am using an API to fetch some data and then injecting it into the dialog box using data option of MatDialog. Data is being injected successfully and also accessible in the dialog component. I'm using ngx-json-viewer package to display this data in JSON view but it's not working. Here's how I'm opening the dialog box and passing data into it-

const logDetailsDialogRef = this.dialog.open(logDetailsDialog, {
    data: {
        logDetails
    }
});

And here is what I am using on my template page-

<ngx-json-viewer [json]="data.logDetails"></ngx-json-viewer>
ess.etch
  • 11
  • 3

1 Answers1

0

You must inject @Inject(MAT_DIALOG_DATA) public data in your constructor.

  constructor(
        @Inject(MAT_DIALOG_DATA) public dataF,
        private sanitizer: DomSanitizer,
    
      )
    
     ngOnInit(): void {
    
    
      this.data = this.dataF;
    
    
      }

this remains the same:

const logDetailsDialogRef = this.dialog.open(logDetailsDialog, {
    data: {
        logDetails
    }
});
Olaru Alina
  • 458
  • 4
  • 8
  • already doing that but haven't mentioned the code in question. `constructor(@Inject(MAT_DIALOG_DATA) public data) {}` My problem is not the data injection. Data is being injected successfully and is accessible in the dialog template (as I mentioned above). I just want to show that data in **json view** – ess.etch Jan 22 '21 at 04:37