Toast & snackbar
Use toast and snackbars to post updates to the users without interrupting them. These notifications can be top/bottom positioned and come in different colors.
Demo
Top or bottom, in a number of preset colors, use the toast to inform users. Perfect for feedback on data save, event creation and much more.
constructor(public notify: Notifications) { }
this.notify.toast({
message: 'Message sent'
});
this.notify.toast({
message: 'Message sent',
display: 'top'
});
this.notify.toast({
message: 'Message sent',
color: 'primary'
});
this.notify.toast({
message: 'Message sent',
color: 'secondary'
});
this.notify.toast({
message: 'Message sent',
color: 'success'
});
this.notify.toast({
message: 'Message sent',
color: 'danger'
});
this.notify.toast({
message: 'Message sent',
color: 'warning'
});
this.notify.toast({
message: 'Message sent',
color: 'info'
});
The snackbar can be rendered with or without and action. Actions can have custom labels and when clicked can call any custom code.
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { MbscModule, Notifications, setOptions } from '@mobiscroll/angular';
setOptions({
theme: ' ',
themeVariant: ' ',
});
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
standalone: true,
imports: [CommonModule, MbscModule],
})
export class AppComponent {
constructor(public notify: Notifications) {}
bottomToast(): void {
this.notify.toast({
message: 'Message sent',
});
}
topToast(): void {
this.notify.toast({
message: 'Message sent',
display: 'top',
});
}
primaryToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'primary',
});
}
secondaryToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'secondary',
});
}
successToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'success',
});
}
dangerToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'danger',
});
}
warningToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'warning',
});
}
infoToast(): void {
this.notify.toast({
message: 'Message sent',
color: 'info',
});
}
bottomSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
});
}
topSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
display: 'top',
});
}
actionSnackbar(): void {
this.notify.snackbar({
message: 'Connection timed out. Showing limited messages.',
button: {
text: 'Retry',
action: () => {
this.notify.toast({
message: 'Retrying...',
});
},
},
});
}
primarySnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'primary',
});
}
secondarySnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'secondary',
});
}
successSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'success',
});
}
dangerSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'danger',
});
}
warningSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'warning',
});
}
infoSnackbar(): void {
this.notify.snackbar({
message: 'Your draft has been discarded',
color: 'info',
});
}
}
<mbsc-page>
<div class="mbsc-form-group">
<div class="mbsc-form-group-title">Toast</div>
<div class="mbsc-button-group-block">
<mbsc-button (click)="bottomToast()">Bottom toast</mbsc-button>
<mbsc-button (click)="topToast()">Top toast</mbsc-button>
<mbsc-button (click)="primaryToast()">Primary toast</mbsc-button>
<mbsc-button (click)="secondaryToast()">Secondary toast</mbsc-button>
<mbsc-button (click)="successToast()">Success toast</mbsc-button>
<mbsc-button (click)="dangerToast()">Danger toast</mbsc-button>
<mbsc-button (click)="warningToast()">Warning toast</mbsc-button>
<mbsc-button (click)="infoToast()">Info toast</mbsc-button>
</div>
</div>
<div class="mbsc-form-group">
<div class="mbsc-form-group-title">Snackbar</div>
<div class="mbsc-button-group-block">
<mbsc-button (click)="bottomSnackbar()">Bottom snackbar</mbsc-button>
<mbsc-button (click)="topSnackbar()">Top snackbar</mbsc-button>
<mbsc-button (click)="actionSnackbar()">Snackbar with action</mbsc-button>
<mbsc-button (click)="primarySnackbar()">Primary snackbar</mbsc-button>
<mbsc-button (click)="secondarySnackbar()">Secondary snackbar</mbsc-button>
<mbsc-button (click)="successSnackbar()">Success snackbar</mbsc-button>
<mbsc-button (click)="dangerSnackbar()">Danger snackbar</mbsc-button>
<mbsc-button (click)="warningSnackbar()">Warning snackbar</mbsc-button>
<mbsc-button (click)="infoSnackbar()">Info snackbar</mbsc-button>
</div>
</div>
</mbsc-page>