projects/maplander/core/src/lib/snackbar/snack-bar.service.ts
Properties |
|
Methods |
|
constructor(_platform: Platform, _snackBar: MatSnackBar)
|
|||||||||
Parameters :
|
Public closeSnackBar |
closeSnackBar()
|
Returns :
void
|
Public setMessage | ||||||||||||||||||
setMessage(message: string, action: string, duration: number, horizontal?: any, vertical?: any)
|
||||||||||||||||||
Parameters :
Returns :
void
|
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();
}
}