Primitives
A toast is a non-modal, unobtrusive window element used to display brief, auto-expiring messages to the user.
Import the Toast primitives from ng-primitives/toast
.
import { NgpToast } from 'ng-primitives/toast';
Assemble the toast directives in your template.
<button (click)="toast.show()">Show Toast</button>
<ng-template ngpToast #toast="ngpToast">
<div>...</div>
</ng-template>
To show a toast, call the show
method on the ngpToast
directive.
The following directives are available to import from the ng-primitives/toast
package:
[ngpToast]
ngpToast
The following data attributes are applied to the first child of the ngpToast
ng-template:
Attribute | Description | Value |
---|---|---|
data-toast |
The visible state of the toast. | visible | hidden |
data-position |
The position of the toast. | start | center | end |
data-gravity |
The gravity of the toast. | top | bottom |
You can configure the default options for all toasts in your application by using the provideNgpToastConfig
function in a providers array.
import { provideToastConfig } from 'ng-primitives/toast';
bootstrapApplication(AppComponent, {
providers: [
provideToastConfig({
duration: 5000,
position: 'center',
gravity: 'top',
stopOnHover: false,
ariaLive: 'assertive',
gap: 16,
}),
],
});
Copyright © 2024 Angular Primitives