@ng-web-apis/notification
v4.12.2
Published
A library for declarative use of Notification API with Angular
Readme
Notification API for Angular
This is a library for declarative use of Notification API with Angular.
Install
npm i @ng-web-apis/notificationUsage
- Import the
NotificationServiceinto your Angular component or service where you want to use it.
import {NotificationService} from '@ng-web-apis/notification';- Inject the
NotificationServiceinto your component's constructor or withinject(Angular 14+).
// in constructor
constructor(private notificationAPIService: NotificationService) {}
// via inject
notificationAPIService = inject(NotificationService);- Use the
requestPermissionandopenmethods 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
