@ng-web-apis/notification
TypeScript icon, indicating that this package has built-in type declarations

4.11.1 • Public • Published

ng-web-apis logo Notification API for Angular

npm version npm bundle size codecov

This is a library for declarative use of Notification API with Angular.

Install

npm i @ng-web-apis/notification

Usage

  1. Import the NotificationService into your Angular component or service where you want to use it.
import {NotificationService} from '@ng-web-apis/notification';
  1. Inject the NotificationService into your component's constructor or with inject (Angular 14+).
// in constructor
constructor(private notificationAPIService: NotificationService) {}

// via inject
notificationAPIService = inject(NotificationService);
  1. Use the requestPermission and open 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

Readme

Keywords

Package Sidebar

Install

npm i @ng-web-apis/notification

Weekly Downloads

18

Version

4.11.1

License

Apache-2.0

Unpacked Size

31.5 kB

Total Files

13

Last publish

Collaborators

  • marsibarsi
  • waterplea
  • vladimir.potekhin
  • defenderbass