Having trouble getting help?
Contact Support
Contact Support
Play an audio before open the toast in Angular Toast component
27 Apr 20243 minutes to read
Here below sample demonstrates to playing audio background while opening toast. Here we have included audio play codes into beforeOpen event Function.
If you want to stop the audio after displaying toast use
open
event in Toast. please check the Toast Eventsapi's
for further customization.
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: `
<div id="toast_target"></div>
<button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
<ejs-toast #element (beforeOpen)="onBeforeOpen($event)" [position] = 'position' >
<ng-template #title>
<div>Matt sent you a friend request</div>
</ng-template>
<ng-template #content>
<div>Hey, wanna dress up as wizards and ride our hoverboards?</div>
</ng-template>
</ejs-toast>
`
})
export class AppComponent {
@ViewChild('element') public element: any;
public position = { X: 'Right', Y: 'Bottom' };
onBeforeOpen(e: any) {
let audio: HTMLAudioElement = new Audio('https://drive.google.com/uc?export=download&id=1M95VOpto1cQ4FQHzNBaLf0WFQglrtWi7');
audio.play();
}
btnClick(args: any) {
this.toastShow();
}
toastShow() {
setTimeout(() => {
this.element.show();
}, 0);
}
ngAfterViewInit() {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));