@ng-web-apis/notification
v5.1.0
Published
A library for declarative use of Notification API with Angular
Downloads
297
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
WaNotificationServiceinto your Angular component or service where you want to use it.
import {WaNotificationService} from '@ng-web-apis/notification';- Inject the
WaNotificationServiceinto your component.
// via inject
notificationAPIService = inject(WaNotificationService);- 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
