src/app/shared/helper.service.ts
        
| Methods | 
| constructor(snackBar: MatSnackBar, dialog: MatDialog) | |||||||||
| Defined in src/app/shared/helper.service.ts:9 | |||||||||
| 
                                    Parameters :
                                     
 | 
| Private parseMessage | ||||||
| parseMessage(message: string | object) | ||||||
| Defined in src/app/shared/helper.service.ts:12 | ||||||
| 
                        Parameters :
                        
                         
 
                        Returns :          any | 
| showConfirmation | ||||||||||||
| showConfirmation(message: string | object, title?: string, confirmButtonText?: string) | ||||||||||||
| Defined in src/app/shared/helper.service.ts:33 | ||||||||||||
| 
                        Parameters :
                        
                         
 
                        Returns :          any | 
| showError | ||||||
| showError(message: string | object) | ||||||
| Defined in src/app/shared/helper.service.ts:18 | ||||||
| 
                        Parameters :
                        
                         
 
                        Returns :          void | 
| showSnackBar | ||||||
| showSnackBar(message: string | object) | ||||||
| Defined in src/app/shared/helper.service.ts:27 | ||||||
| 
                        Parameters :
                        
                         
 
                        Returns :          void | 
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { AlertDialogComponent } from './dialog/alert-dialog/alert-dialog.component';
import { ConfirmDialogComponent } from './dialog/confirm-dialog/confirm-dialog.component';
@Injectable()
export class HelperService {
  constructor(protected snackBar: MatSnackBar, protected dialog: MatDialog) {}
  private parseMessage(message: string | object) {
    return typeof message === 'string'
      ? message
      : JSON.stringify(message, null, 2);
  }
  showError(message: string | object) {
    this.dialog.open(AlertDialogComponent, {
      data: {
        title: 'Error',
        message: this.parseMessage(message),
      },
    });
  }
  showSnackBar(message: string | object) {
    this.snackBar.open(this.parseMessage(message), 'OK', {
      duration: 2000,
    });
  }
  showConfirmation(
    message: string | object,
    title?: string,
    confirmButtonText?: string
  ) {
    return this.dialog
      .open(ConfirmDialogComponent, {
        data: {
          message: this.parseMessage(message),
          title,
          confirmButtonText,
        },
      })
      .afterClosed()
      .toPromise();
  }
}