Template in Angular Message component

14 Nov 20223 minutes to read

The message supports templates that allows the user to customize the content with a custom structure. The content can be a string, paragraph, or any other HTML element. The template can be rendered through the content property or added directly to the HTML element.

In the following sample, the Message component content is customized with HTML elements and Angular Button components, which are directly added to the HTML element.

import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';
import { MessageComponent } from '@syncfusion/ej2-angular-notifications';

    selector: 'app-root',
    template: `<div class="msg-template-section">
        <div class="content-section">
            <button ejs-button #showBtn id='showBtn' content='Show pull request' cssClass="e-outline e-primary e-success msg-hidden"
            <ejs-message #msg_template id="msg_template" severity="Success" (closed)="closed()">
                <ng-template #content>
                    <h1>Merged pull request</h1>
                    <p>Pull request #41 merged after a successful build</p>
                    <button ejs-button id='commitBtn' cssClass='e-link' content='View commit'></button>
                    <button ejs-button #closeBtn id='closeBtn' cssClass='e-link' content='Dismiss' (click)="dismissClick()"></button>
export class AppComponent{
    @ViewChild('showBtn') private showBtn: ButtonComponent;
    @ViewChild('msg_template') private msgTemplate: MessageComponent;

    public showClick(): void {
        this.msgTemplate.visible = true;

    public dismissClick(): void {
        this.msgTemplate.visible = false;

    public closed(): void {
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MessageModule } from '@syncfusion/ej2-angular-notifications';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';

 * Module
    imports: [
        BrowserModule, MessageModule, ButtonModule
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';