Having trouble getting help?
Contact Support
Contact Support
Action buttons in Angular Toast component
27 Apr 20243 minutes to read
You can include action Buttons into toast by adding buttons
property. You can bind collections of Essential JS 2 Button Model to model
property inside buttons property, You can also include click event callback function, for each button.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToastModule } from '@syncfusion/ej2-angular-notifications'
import { ButtonModule, CheckBoxModule , RadioButtonModule } from '@syncfusion/ej2-angular-buttons'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { DatePickerModule } from '@syncfusion/ej2-angular-calendars'
import { Component, ViewChild } from '@angular/core';
import { closest} from '@syncfusion/ej2-base';
@Component({
imports: [
ToastModule, ButtonModule, CheckBoxModule , RadioButtonModule, DropDownListModule, DatePickerModule
],
standalone: true,
selector: 'app-root',
template: `
<div id="toast_target"></div>
<button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
<ejs-toast id='elementToastTime' #element (created)="onCreate($event)" width='230px' height='250px' title= 'Anjolie Stokes' [buttons]='buttons'
content= '<p><img src="./laura.png"></p>' [position] = 'position' > </ejs-toast>`
})
export class AppComponent {
@ViewChild('element') public element: any;
public position = { X: "Right", Y: "Bottom" };
public buttons = [{ model: { content: "Ignore" }, click: this.btnToastClick.bind(this)}, {model: { content: "reply" }}];
btnToastClick(e: any) {
const toastEle = closest(e.target, '.e-toast');
this.element.hide(toastEle);
}
onCreate(args: any) {
this.toastShow();
}
btnClick(args: any) {
this.toastShow();
}
toastShow() {
setTimeout(
() => {
this.element.show();
}, 700);
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));