##Toast
The Ignite UI for Angular Toast component provides information and warning messages that are non-interactive and cannot be dismissed by the user. Notifications can be displayed at the bottom, the middle, or the top of the page.
Toast Demo
Note
To start using Ignite UI for Angular components in your own projects, make sure you have configured all necessary dependencies and have performed the proper setup of your project. You can learn how to do this in the installation topic.
###Usage
To get started with the Ignite UI for Angular Toast, let's first import the IgxToastModule
in our app.module.ts file:
// app.module.ts
...
import { IgxToastModule } from 'igniteui-angular';
@NgModule({
...
imports: [..., IgxToastModule],
...
})
export class AppModule {}
Show Toast
In order to display the toast component, use its open()
method and call it on a button click. Use the message
input to set a notification.
<!--sample.component.html-->
<button igxButton="raised" (click)="toast.open()">Show notification</button>
<igx-toast #toast message="Notification displayed"></igx-toast>
If the sample is configured properly, a toast appears displaying a notification when the button is clicked.
Hide/Auto Hide
Once opened, the toast disappears after a period specified by the displayTime
input which is set initially to 4000 milliseconds. This behavior is enabled by default but you can change this by setting autoHide
to false. In this way, the toast remains visible. Using the toast close()
method, you can close the component.
<!--sample.component.html-->
<button igxButton="raised" (click)="toast.open()">SHOW TOAST</button>
<button igxButton="raised" (click)="toast.close()">HIDE TOAST</button>
<igx-toast #toast message="Notification displayed" [autoHide]="false"></igx-toast>
If the sample is configured properly, the toast appears when the 'SHOW' button is clicked. The auto hide feature is disabled and the toast disappears on 'HIDE' button click.
Display Time
Use displayTime
and set it to an interval in milliseconds to configure how long the toast component is visible.
<!--sample.component.html-->
<button igxButton="raised" (click)="toast.open()">Show notification</button>
<igx-toast #toast message="Notification displayed" displayTime="1000"></igx-toast>
If the sample is configured properly, the toast auto hides faster.
Positioning
Use position
to configure where the toast appears. By default, the toast is displayed at the bottom of the page. In the sample below, we set notification to appear at the top position.
<!--sample.component.html-->
<div>
<button igxButton="raised" (click)="open(toast)">Show notification on top</button>
<igx-toast #toast message="Notification displayed" [position]="toastPosition"></igx-toast>
</div>
// sample.component.ts
import { IgxToastPosition } from 'igniteui-angular';
...
public toastPosition: IgxToastPosition;
public open(toast) {
this.toastPosition = IgxToastPosition.Top;
toast.open();
}
...
API References
In this article we learned how to use and configure the IgxToastComponent
. For more details in regards its API, take a look at the links below:
Styles:
###Additional Resources
Our community is active and always welcoming to new ideas. * [Ignite UI for Angular **Forums**](https://www.infragistics.com/community/forums/f/ignite-ui-for-angular) * [Ignite UI for Angular **GitHub**](https://github.com/IgniteUI/igniteui-angular)