@ng-web-apis/notification
v4.11.1
Published
A library for declarative use of Notification API with Angular
Downloads
631
Readme
Notification API for Angular
This is a library for declarative use of Notification API with Angular.
Install
npm i @ng-web-apis/notification
Usage
- Import the
NotificationService
into your Angular component or service where you want to use it.
import {NotificationService} from '@ng-web-apis/notification';
- Inject the
NotificationService
into your component's constructor or withinject
(Angular 14+).
// in constructor
constructor(private notificationAPIService: NotificationService) {}
// via inject
notificationAPIService = inject(NotificationService);
- Use the
requestPermission
andopen
methods to request permission and open a notification.
this.notificationAPIService
.requestPermission()
.pipe(
filter((permission) => permission === 'granted'),
switchMap(() =>
this.notificationAPIService.open('Hello world!', {
body: 'This is a notification',
requireInteraction: true,
}),
),
)
.subscribe();
Demo
You can try online demo here
See also
Other Web APIs for Angular by @ng-web-apis