Angular UI Components Documentation
Angular Notification Component
The Notification component for Angular represents a widget which displays an unobtrusive notification to the user. Multiple instances of the same notification can be shown at the same time.
1. Installation
The easiest way to get started with jQWidgets UI for Angular is to use the Angular CLI Tool. To scaffold your project structure, follow its installation instructions.npm install -g @angular/cli ng new jqwidgets-project cd jqwidgets-project
Install jQWidgets
jQWidgets Angular UI comes packaged with Angular CLI schematics to make creating Angular applications easier. Schematics are included with both @angular/cdk and jqwidgets-ng. Once you install the npm packages, they will be available through the Angular CLI.Angular CLI supports the addition of packages through the ng add command. The ng add command provides faster and more user-friendly package installation. To install the jQWidgets UI for Angular package, use ng add and add the name of the NPM package:
ng add jqwidgets-ng
Alternatively, you can use the standard installation (Manual Setup)
jQWidgets UI for Angular is distributed as jqwidgets-ng NPM package
- Download and install the package.
npm install jqwidgets-ng
- Adding CSS reference
The following CSS file is available in ../node_modules/jqwidgets-ng/ package folder. This can be referenced in [src/styles.css] using following code.@import 'jqwidgets-ng/jqwidgets/styles/jqx.base.css';
Another way to achieve the same is to edit the angular.json file and in the styles add the style."styles": [ "node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css" ]
2. Add the HTML for jQWidgets component in src/app/app.component.html
app.component.html
<!--Notifications-->
<jqxNotification [theme]="'fluent'" #msgNotification
[width]="250" [position]="'top-right'" [opacity]="0.9" [autoOpen]="false"
[autoClose]="true" [animationOpenDelay]="800" [autoCloseDelay]="3000" [template]="'info'">
<div>
Welcome to our website.
</div>
</jqxNotification>
<jqxNotification [theme]="'fluent'" #timeNotification
[width]="250" [position]="'top-right'" [opacity]="0.9" [autoOpen]="false"
[autoClose]="true" [animationOpenDelay]="800" [autoCloseDelay]="3000" [template]="'time'">
<div>Current time: <span id="currentTime" style="font-weight: bold;"></span>.</div>
</jqxNotification>
<!--Layout-->
<jqxButton [theme]="'fluent'" [width]="230" [height]="30" (onClick)="onClickOpenMessageNotification()">
Open a message notification
</jqxButton>
<br /><br />
<jqxButton [theme]="'fluent'" [width]="230" [height]="30" (onClick)="onClickOpenTimeNotification()">
Open a current time notification
</jqxButton>
3. Setup Component Logic
app.component.ts
import { Component, ViewChild } from '@angular/core';
import { jqxNotificationModule, jqxNotificationComponent } from 'jqwidgets-ng/jqxnotification';
import { jqxButtonComponent, jqxButtonModule } from 'jqwidgets-ng/jqxbuttons';
@Component({
selector: 'app-root',
imports: [jqxNotificationModule, jqxButtonModule],
standalone: true,
templateUrl: './app.component.html'
})
export class AppComponent {
@ViewChild('msgNotification') msgNotification: jqxNotificationComponent;
@ViewChild('timeNotification') timeNotification: jqxNotificationComponent;
onClickOpenMessageNotification(): void {
this.msgNotification.open();
}
onClickOpenTimeNotification(): void {
let date = new Date();
let minutes = date.getMinutes();
let minutesString: String = '';
if (minutes < 10) {
minutesString = "0" + minutes;
} else {
minutesString = "" + minutes;
}
let seconds = date.getSeconds();
let secondsString: String = '';
if (seconds < 10) {
secondsString = "0" + seconds;
} else {
secondsString = "" + seconds;
}
let timeSpan = document.getElementById('currentTime');
timeSpan.innerText = date.getHours() + ":" + minutesString + ":" + secondsString;
this.timeNotification.open();
}
}