Having trouble getting help?
Contact Support
Contact Support
Render template in toast using angular template in Angular Toast component
27 Apr 20242 minutes to read
You can also render the template support in Toast using the Angular ng-template. We need to use this ng-template within the e-toast tag with #template attribute, which is mandatory to render template property. Also you don’t need to use the template property if you used this ng-template.
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';
@Component({
imports: [
ToastModule, ButtonModule, CheckBoxModule , RadioButtonModule, DropDownListModule, DatePickerModule
],
standalone: true,
selector: 'app-root',
template: `
<button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
<ejs-toast #element (created)="onCreate($event)" [position] = 'position' >
<ng-template #template>
<div id="template_toast_ele">
<ejs-datepicker></ejs-datepicker>
</div>
</ng-template>
</ejs-toast>`
})
export class AppComponent {
@ViewChild('element') public element: any;
public position = { X: 'Right', Y: 'Bottom' };
onCreate(args: any){
setTimeout(
() => {
this.element.show();
}, 200);
}
btnClick(args: any) {
this.toastShow();
}
toastShow() {
this.element.show();
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));