Getting started with Angular Message component
11 Jul 20243 minutes to read
This section explains the steps required to create a simple Angular Message component and configure its available functionalities.
Setup Angular Environment
Use Angular CLI
to setup the Angular applications. To install Angular CLI, use the following command.
npm install -g @angular/cli
Create an Angular Application
Start a new Angular application using the following Angular CLI command.
ng new my-app
cd my-app
Installing Syncfusion Notification package
Syncfusion packages are distributed in npm as @syncfusion
scoped packages. Get all the Angular Syncfusion package from npm link.
Currently, Syncfusion provides two types of package structures for Angular components. They are:
- Ivy library distribution package format.
- Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.
Ivy library distribution package
Syncfusion Angular packages(>=20.2.36
) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package, use the following command.
Add @syncfusion/ej2-angular-notifications
package to the application.
npm install @syncfusion/ej2-angular-notifications --save
Angular compatibility compiled package(ngcc)
For Angular version below 12, use the legacy (ngcc) package of the Syncfusion Angular components. To download the ngcc
package, use the following command.
Add @syncfusion/ej2-angular-notifications@ngcc
package to the application.
npm install @syncfusion/ej2-angular-notifications@ngcc --save
To mention the ngcc package in the package.json
file, add the suffix -ngcc
with the package version as follows.
@syncfusion/ej2-angular-notifications:"20.3.47-ngcc"
Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.
Adding CSS Reference
Add Message component’s styles as given in the following styles.css.
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-notifications/styles/message/material.css';
Add Message component
Modify the template in the [src/app/app.component.ts] file to render the Message component. Add the Angular Message by using the <ejs-message>
selector in the template
section of the app.component.ts file.
import { MessageModule } from '@syncfusion/ej2-angular-notifications'
import { Component } from '@angular/core';
@Component({
imports: [
MessageModule
],
standalone: true,
selector: 'app-root',
template: '<ejs-message content="Please read the comments carefully"></ejs-message>'
})
export class AppComponent{
}
Run the application
Use the following command to run the application in the browser.
ng serve --open
The output will appear as follows.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MessageModule } from '@syncfusion/ej2-angular-notifications'
import { Component } from '@angular/core';
@Component({
imports: [
MessageModule
],
standalone: true,
selector: 'app-root',
template: '<ejs-message content="Please read the comments carefully"></ejs-message>'
})
export class AppComponent{
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));