Search results

Template

The Template property in toast can be defined as HTML element, this can be either a string or selector.

The HTML element tag can be given as a string for the Template property.

template: "<div>Toast Content</div>"

The Template property allows getting the template content using the query selector. Here, the element ‘ID’ attribute is specified in the template.

template: "#Template"
Source
Preview
index.ts
index.html
import { Toast, ToastOpenArgs, ToastCloseArgs, ToastBeforeOpenArgs } from '@syncfusion/ej2-notifications';
import { DropDownList, ChangeEventArgs } from '@syncfusion/ej2-dropdowns';
import { compile, Browser, closest } from '@syncfusion/ej2-base';

let toast: Toast = new Toast({
  template: document.getElementById('template_toast_ele').innerHTML,
  position:  { X: 'Right', Y: 'Bottom' },
  target: document.body,
  extendedTimeout: 0,
  timeOut: 120000
});
toast.appendTo('#element');
toast.show();

let btnEle: HTMLElement = document.getElementById('toast_mail_remainder');
let snoozeFlag: boolean = false;

document.getElementById('show_toast').onclick = () => {
    toast.show();
}
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 Toast</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
      <div class='row'> <button class="e-btn" id="show_toast"> Show Toast</button> </div>
      <div id="template_toast"> <div id='element'></div> </div>
        
        <br/><br/>
        <div id='result'></div>
    </div>
    <script id="template_toast_ele" type="text/x-template">
    <div id='template_toast' style="display: none">
        <div class="horizontal-align">
            <div class='toast-content'>
                <div class='toast-title'>
                    Weekend Alarm
                </div>
                <div class='toast-message'> With traffic, its likely to take 45 minutes to get to jenny's 24th Birthday Bash at Hillside Bar, 454 E.
                    Olive Way by 10:00PM </div>
            </div>
        </div>
        <img src="https://ej2.syncfusion.com/demos/src/toast/resource/map.jpg" width="100%" height="70%">
    </div>
</script>
</body>

</html>

See Also