File

projects/maplander/core/src/lib/snackbar/snack-bar.service.ts

Index

Properties
Methods

Constructor

constructor(_platform: Platform, _snackBar: MatSnackBar)
Parameters :
Name Type Optional
_platform Platform No
_snackBar MatSnackBar No

Methods

Public closeSnackBar
closeSnackBar()
Returns : void
Public setMessage
setMessage(message: string, action: string, duration: number, horizontal?: any, vertical?: any)
Parameters :
Name Type Optional
message string No
action string No
duration number No
horizontal any Yes
vertical any Yes
Returns : void

Properties

Private _snackBarRef
Type : MatSnackBarRef<SimpleSnackBar>
import {Injectable} from '@angular/core';
import {MatSnackBar, MatSnackBarRef, SimpleSnackBar} from '@angular/material/snack-bar';
import {Platform} from '@angular/cdk/platform';

@Injectable()
export class SnackBarService {

  private _snackBarRef: MatSnackBarRef<SimpleSnackBar>;

  constructor(private _platform: Platform, private _snackBar: MatSnackBar) {
  }

  public setMessage(message: string, action: string, duration: number, horizontal?: any, vertical?: any): void {
    const h = (horizontal) ? horizontal : 'end';
    const v = (vertical) ? vertical : 'bottom';
    if (this._platform.isBrowser) {
      this._snackBarRef = this._snackBar.open(message, action, {
        duration: duration,
        horizontalPosition: h,
        verticalPosition: v
      });
    }
  }

  public closeSnackBar(): void {
    if (this._snackBarRef === undefined) {
      return;
    }
    this._snackBarRef.dismiss();
  }
}

result-matching ""

    No results matching ""