npm.io
1.0.3 • Published 3 years ago

@kovalenko/snack-bar

Licence
MIT
Version
1.0.3
Deps
1
Size
24 kB
Vulns
0
Weekly
0

Material Snackbar with default action

This module provides a service to open Material Snackbar with default dismiss action.

Installation

npm install @kovalenko/snack-bar

Usage

First, import the SnackBarModule to your module:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {SnackBarModule} from '@kovalenko/snack-bar';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {DialogComponent} from './app';

@NgModule({
  imports: [BrowserModule, SnackBarModule],
  declarations: [DialogComponent],
  bootstrap: [DialogComponent],
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(DialogComponent);

Then inject SnackBarService:

import {Component} from '@angular/core';
import {SnackBarService, snack} from 'snack-bar';

@Component({
  template: ``
})
export class DialogComponent {

  constructor(
    private readonly snackBarService: SnackBarService,
  ) { }

  ngOnInit(): void {
    // Set default action title globally
    this.snackBarService.defaultAction = 'Close';
    
    // Launch snackbar
    this.snackBarService.open('Privet', snack.error);
  }
}
API
SnackBarService
Properties

defaultAction?: string;

Methods
open
Opens a snackbar with a message and default action
Parameters
message
string
The message to show in the snackbar
config?
MatSnackBarConfig<any>
Additional configuration options for the snackbar
action?
string
The label for the snackbar action
Returns
MatSnackBarRef<any>

License

MIT

Keywords