Search results

Configuring options

This section explains on customizing the Toast appearance using built-in APIs.

Title and content template

Toast can be created with the notification message. The message contains title and content of the Toasts. Title and contents are adaptable in any resolution.

Title or Content property can be given as HTML element/element ID as a string that can be displayed as a Toast.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.html
index.css
import { Component, ViewChild } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `
        <div id="toast_target"></div>
        <button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
        <ejs-toast #element (created)="onCreate($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') element;
    public position = { X: 'Right' };

    onCreate() {
      this.toastShow();
    }
    btnClick() {
      this.toastShow();
    }
    toastShow() {
          setTimeout(
        () => {
            this.element.show();
        }, 700);
    }
}
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 { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, ToastModule, ButtonModule, CheckBoxModule , RadioButtonModule, DropDownListModule, DatePickerModule
    ],
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion Angular Toast Sample</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="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link href="index.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <app-root>
        <div id='loader'>LOADING....</div>
    </app-root>
    <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="http://npmci.syncfusion.com/development/demos/src/toast/resource/map.jpg" width="100%" height="70%">
        </div>
    </script>
</body>
</html>
/* csslint ignore:start */
#container {
    margin: 25px;
}

#elementToastTime .e-toast {
    width: 500px;
    height: 147px;
}

#elementToastTime {
    text-align: center;
}

#elementToastTime img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
}

#elementToastTime .e-toast-message {
    width: inherit;
}

#sample_container {
    margin: 10px;
}

body>#element .e-toast {
    width: 400px !important;
}

#template_toast .horizontal-align {
    margin: 10px 0;
}

#template_toast .horizontal-align .toast-content .toast-message {
    opacity: 0.4;
}

#template_toast .horizontal-align .toast-content {
    display: inline-flex;
    flex: 1;
    flex-direction: column;
    margin-left: 10px;
}

#loader {
    color: #008cff;
    height: 40px;
    left: 45%;
    position: absolute;
    top: 45%;
    width: 30%;
}

.progress {
    height: 20px;
    position: relative;
    margin: 20px 0 20px 0;
    background: #555;
    -moz-border-radius: 25px;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.3);
}

.progress span {
    background-color: #f0a3a3;
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f0a3a3), color-stop(1, #f42323));
    display: block;
    height: 100%;
    border-radius: 10px;
    width: 50%;
    position: relative;
    overflow: hidden;
}

.progress span::after {
    background-image: -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, rgba(255, 255, 255, .2)), color-stop(.25, transparent), color-stop(.5, transparent), color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.75, rgba(255, 255, 255, .2)), color-stop(.75, transparent), to(transparent));
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-size: 50px 50px;
    -webkit-animation: moveAnimate 2s linear infinite;
    overflow: hidden;
}

@-webkit-keyframes moveAnimate {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 50px 50px;
    }
}
/* csslint ignore:end */

Specifying custom target

By default toast can be rendered in the document body, we can change the target position for toast rendering using target property. Based on the target position will update.

Close Button

In default showCloseButton is not enabled. We can enable it by setting true value. Before expiring toast we can use to close or destroy toasts manually.

Progress bar

In default showProgressBar is not enabled. If we enabled it can visually indicate how long time to get toast expires. Based on the timeOut property Progress bar will appear.

Newest on top

In default, newly created toasts will append next with existing toast. We can change the Sequence like inserting before the toast, by enabling the newestOnTop.

Here below sample demonstrates the combination of target, showCloseButton, showProgressBar and newestOnTop properties in toast.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.html
index.css
import { Component, ViewChild } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `
        <div id="toast_target"></div>
        <button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
        <ejs-toast #element (created)="onCreate($event)" showCloseButton=true newestOnTop=true showProgressBar=true target='#toast_target' [position] = 'position' >
            <ng-template #title>
                <div>File Downloading</div>
            </ng-template>
            <ng-template #content>
                <div class="progress"><span style="width: 80%"></span></div>
            </ng-template>
        </ejs-toast>`
})

export class AppComponent {
    @ViewChild('element') element;
    public position = { X: 'Center' };

    onCreate() {
      this.element.show();
    }
    btnClick() {
      this.element.show();
    }
}
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 { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, ToastModule, ButtonModule, CheckBoxModule , RadioButtonModule, DropDownListModule, DatePickerModule
    ],
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion Angular Toast Sample</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="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link href="index.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <app-root>
        <div id='loader'>LOADING....</div>
    </app-root>
    <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="http://npmci.syncfusion.com/development/demos/src/toast/resource/map.jpg" width="100%" height="70%">
        </div>
    </script>
</body>
</html>
/* csslint ignore:start */
#container {
    margin: 25px;
}

#elementToastTime .e-toast {
    width: 500px;
    height: 147px;
}

#elementToastTime {
    text-align: center;
}

#elementToastTime img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
}

#elementToastTime .e-toast-message {
    width: inherit;
}

#sample_container {
    margin: 10px;
}

body>#element .e-toast {
    width: 400px !important;
}

#template_toast .horizontal-align {
    margin: 10px 0;
}

#template_toast .horizontal-align .toast-content .toast-message {
    opacity: 0.4;
}

#template_toast .horizontal-align .toast-content {
    display: inline-flex;
    flex: 1;
    flex-direction: column;
    margin-left: 10px;
}

#loader {
    color: #008cff;
    height: 40px;
    left: 45%;
    position: absolute;
    top: 45%;
    width: 30%;
}

.progress {
    height: 20px;
    position: relative;
    margin: 20px 0 20px 0;
    background: #555;
    -moz-border-radius: 25px;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.3);
}

.progress span {
    background-color: #f0a3a3;
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f0a3a3), color-stop(1, #f42323));
    display: block;
    height: 100%;
    border-radius: 10px;
    width: 50%;
    position: relative;
    overflow: hidden;
}

.progress span::after {
    background-image: -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, rgba(255, 255, 255, .2)), color-stop(.25, transparent), color-stop(.5, transparent), color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.75, rgba(255, 255, 255, .2)), color-stop(.75, transparent), to(transparent));
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-size: 50px 50px;
    -webkit-animation: moveAnimate 2s linear infinite;
    overflow: hidden;
}

@-webkit-keyframes moveAnimate {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 50px 50px;
    }
}
/* csslint ignore:end */

Width and height

we can set toast dimensions through width and height property. This will individually set all toasts, we can create different custom dimension toasts.

In default toast can be rendered with ‘300px’ width with ‘auto’ height

In mobile device toast default width gets ‘100%’ width of the page. When we sets toast width as ‘100%’ toast will occupies full width and displayed top or bottom based on position Y property.

Both width and height property allows setting pixels/numbers/percentage. The number value is considered as pixels.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.html
index.css
import { Component, ViewChild } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `
        <div id="toast_target"></div>
        <div id=sample_container>
         <div id='container'>
            <div class='row' style="padding-top: 20px;margin:0" id= "toast_pos_target">
              <table>
                <tr>
                  <td>
                      <div style='padding:25px 0 0 0;'>
                          <ejs-radiobutton (change)="topChange($event)" label="Top" name="position" value="Top"></ejs-radiobutton>
                      </div>
                  </td>
                  <td>
                      <div style='padding:25px 0 0 0;'>
                         <ejs-radiobutton (change)="bottomChange($event)" label="Bottom" name="position" value="Bottom" checked="true"></ejs-radiobutton>
                      </div>
                  </td>
                </tr>
                <tr>
                   <td>
                     <div style='padding:25px 0 0 0;'>
                         <ejs-checkbox #checkbox label="100% Width" (change)="checkBoxChange($event)"></ejs-checkbox>
                      </div>
                   </td>
                </tr>
              </table>
            </div></div>
        <button ejs-button [isPrimary]="true" (click)="btnClick($event)">Show Toast</button>
        </div>
        <ejs-toast #element (created)="onCreate($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') toast;
    public position = { X: 'Center', Y: 'Bottom' };

    onCreate() {
      this.toastShow();
    }
    btnClick() {
      this.toastShow();
    }
    toastShow() {
          setTimeout(
        () => {
            this.toast.show();
        }, 700);
    }

    bottomChange(e) {
      let toast = this.toast;
        if (e.event.target.checked) {
      toast.position.Y = "Bottom";
      toast.hide('All');
      this.toastShow();
    }
    }

    topChange(e) {
      let toast = this.toast;
      if (e.event.target.checked) {
      toast.position.Y = "Top";
      toast.hide('All');
      this.toastShow();
    }
    }

    checkBoxChange(e) {
      let toast = this.toast;
        if (e.checked) {
            toast.hide('All');
            toast.width = "100%";
            toast.title = "";
            toast.content = "<div class='e-custom'>Take a look at our next generation <b>Javascript</b> <a href='https://ej2.syncfusion.com/home/index.html' target='_blank'>LEARN MORE</a></div>";
            this.toastShow();
        } else {
            toast.hide('All');
            toast.width = 300;
            toast.title = 'Matt sent you a friend request',
            toast.content = 'Hey, wanna dress up as wizards and ride our hoverboards?',
            this.toastShow();
        }
    }
}
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 { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, ToastModule, ButtonModule, CheckBoxModule , RadioButtonModule, DropDownListModule, DatePickerModule
    ],
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion Angular Toast Sample</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="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link href="index.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>
<body>
    <app-root>
        <div id='loader'>LOADING....</div>
    </app-root>
    <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="http://npmci.syncfusion.com/development/demos/src/toast/resource/map.jpg" width="100%" height="70%">
        </div>
    </script>
</body>
</html>
/* csslint ignore:start */
#container {
    margin: 25px;
}

#elementToastTime .e-toast {
    width: 500px;
    height: 147px;
}

#elementToastTime {
    text-align: center;
}

#elementToastTime img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
}

#elementToastTime .e-toast-message {
    width: inherit;
}

#sample_container {
    margin: 10px;
}

body>#element .e-toast {
    width: 400px !important;
}

#template_toast .horizontal-align {
    margin: 10px 0;
}

#template_toast .horizontal-align .toast-content .toast-message {
    opacity: 0.4;
}

#template_toast .horizontal-align .toast-content {
    display: inline-flex;
    flex: 1;
    flex-direction: column;
    margin-left: 10px;
}

#loader {
    color: #008cff;
    height: 40px;
    left: 45%;
    position: absolute;
    top: 45%;
    width: 30%;
}

.progress {
    height: 20px;
    position: relative;
    margin: 20px 0 20px 0;
    background: #555;
    -moz-border-radius: 25px;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.3);
}

.progress span {
    background-color: #f0a3a3;
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f0a3a3), color-stop(1, #f42323));
    display: block;
    height: 100%;
    border-radius: 10px;
    width: 50%;
    position: relative;
    overflow: hidden;
}

.progress span::after {
    background-image: -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, rgba(255, 255, 255, .2)), color-stop(.25, transparent), color-stop(.5, transparent), color-stop(.5, rgba(255, 255, 255, .2)), color-stop(.75, rgba(255, 255, 255, .2)), color-stop(.75, transparent), to(transparent));
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-size: 50px 50px;
    -webkit-animation: moveAnimate 2s linear infinite;
    overflow: hidden;
}

@-webkit-keyframes moveAnimate {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 50px 50px;
    }
}
/* csslint ignore:end */

See Also