/ Message / Customization
Search results

Customization in Angular Message component

21 Dec 2022 / 3 minutes to read

The Message component allows the user to customize the content display positions and appearance. This section explains the details about changing the content alignments and border styles for messages.

Content Alignment

Normally, the message content is aligned to the left. The Message component allows the user to align the message content in the center or right through the built-in classes e-content-center and e-content-right.

The following example demonstrates the message with different content alignments.

Copied to clipboard
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div class="msg-custom-section">
        <div class="content-section">
            <h4>Content Alignment</h4>
            <ejs-message id="msg_content_left" content="Your license has been activated successfully" severity="Success"></ejs-message>
            <ejs-message id="msg_content_center" content="The license will expire today" cssClass="e-content-center" severity="Warning"></ejs-message>
            <ejs-message id="msg_content_right" content="The license key is invalid" cssClass="e-content-right" severity="Error"></ejs-message>
        </div>
    </div>`
})
export class AppComponent{
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MessageModule } from '@syncfusion/ej2-angular-notifications';
import { AppComponent } from './app.component';

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

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

<head>
            <script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"></script>
    <title>Essential JS 2 Message 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="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/material.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.9.0/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>
</body>
</html>

Rounded and Square

To customize the Message component’s appearance, add the custom class to the message through the cssClass property. This custom class will be added to the root element. Based on this custom class, the user can override the message styles at the application level.

The following example shows the rounded and squared appearance of the message, which can be achieved by adding the cssClass property.

Copied to clipboard
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div class="msg-custom-section">
        <div class="content-section">
            <h4>Rounded</h4>
            <ejs-message content="The license will expire today" cssClass="rounded" severity="Warning"></ejs-message>
            <h4>Square</h4>
            <ejs-message content="The license key is invalid" cssClass="square" severity="Error"></ejs-message>
        </div>
    </div>`
})
export class AppComponent{
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MessageModule } from '@syncfusion/ej2-angular-notifications';
import { AppComponent } from './app.component';

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

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

<head>
            <script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"></script>
    <title>Essential JS 2 Message 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="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/material.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.9.0/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>
</body>
</html>

CSS Message

The Essential JS 2 Message has predefined CSS classes that can be defined in the HTML elements, which renders the message without any script reference. This can display a simple message with content and make the code lighter.

The following DOM structure is required to display the simple message with the content.

Copied to clipboard
<div class="e-message">
    <div class="e-msg-content">..content..</div>
</div>

The following DOM structure is required to display the simple message with the content and severity icon.

Copied to clipboard
<div class="e-message">
    <span class="e-msg-icon"></span>
    <div class="e-msg-content">..content..</div>
</div>

The following is the available list of predefined CSS classes to make the appearance of a message.

Class Description
e-message Represents the message wrapper.
e-msg-icon Represents the severity type icon.
e-msg-content Represents the message content.
e-msg-close-icon Represents the close icon.
e-info Represents the information message.
e-success Represents the success message.
e-warning Represents the warning message.
e-error Represents the error message.
e-content-center Aligns the message content to the center.
e-content-right Aligns the message content to the right.

The following example shows the message which renders without any script reference.

Copied to clipboard
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div class="msg-default-section">
        <div class="content-section">
            <div id="msg-default" class="e-message" role="alert">
                <span class="e-msg-icon"></span>
                <div class="e-msg-content">Editing is restricted</div>
            </div>
            <div id="msg-info" class="e-message e-info" role="alert">
                <span class="e-msg-icon"></span>
                <div class="e-msg-content">Please read the comments carefully</div>
            </div>
            <div id="msg-success" class="e-message e-success" role="alert">
                <span class="e-msg-icon"></span>
                <div class="e-msg-content">Your message has been sent successfully</div>
            </div>
            <div id="msg-warning" class="e-message e-warning" role="alert">
                <span class="e-msg-icon"></span>
                <div class="e-msg-content">There was a problem with your network connection</div>
            </div>
            <div id="msg-error" class="e-message e-error" role="alert">
                <span class="e-msg-icon"></span>
                <div class="e-msg-content">A problem occurred while submitting your data</div>
            </div>
        </div>
    </div>`
})
export class AppComponent{
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MessageModule } from '@syncfusion/ej2-angular-notifications';
import { AppComponent } from './app.component';

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

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

<head>
            <script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"></script>
    <title>Essential JS 2 Message 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="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/material.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.9.0/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>
</body>
</html>
Copied to clipboard
#container {
    visibility: hidden;
}

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

.msg-default-section .content-section {
  margin: 0 auto;
  max-width: 450px;
  padding-top: 10px;
}

.msg-default-section .e-message {
  margin: 10px 0;
}