I'm trying to include only snackbar component from material-components repo on Github:
https://github.com/material-components/material-components-web
I'm trying to include only snackbar component from material-components repo on Github:
https://github.com/material-components/material-components-web
You could try https://material.angular.io
HTML
<button md-button (click)="openSnackBar()" aria-label="Show an example snack-bar">
Pizza party
</button>
TS
import {Component} from '@angular/core';
import {MdSnackBar} from '@angular/material';
@Component({
selector: 'snack-bar-component-example',
templateUrl: './snack-bar-component-example.html',
})
export class SnackBarComponentExample {
constructor(public snackBar: MdSnackBar) {}
openSnackBar() {
this.snackBar.openFromComponent(PizzaPartyComponent, {
duration: 500,
});
}
}
@Component({
selector: 'snack-bar-component-example-snack',
templateUrl: './snack-bar-component-example-snack.html',
styleUrls: ['./snack-bar-component-example-snack.css'],
})
export class PizzaPartyComponent {}
example from actual docs https://material.angular.io/components/component/snack-bar
The Blox Material library provides an integration between Material Components for the Web and Angular. It also has bindings for the material-components snackbar component that you want to use.
There is a getting started guide for the library here: https://blox.src.zone/material#/guides/gettingstarted
Documentation and code samples for snackbar messages can be found here: https://blox.src.zone/material#/directives/snackbar
In short, you have to install the @blox/material
library and import its MaterialModule
in your Angular application. That will register an MdcSnackBarService
that can be used to create snackbar messages. All options, settings, and theming possibilities of mdc-snackbar
are available.
If you follow the Getting Started guide and only use the MdcSnackBarService
, your production build will only contain code for the snackbar component.
If you want to do this without an existing integration library, maybe have a look at the sourcecode from Blox Material for inspiration.