Native notifications for your Angular application using the Web Notification API. Works on chrome, firefox, edge, and safari.
Native Notifications
npm i angular-notice
import NotificationsModule and add it to the imports array within your app’s module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NativeNotificationsService } from 'angular-notice'
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [NativeNotificationsService], // add to your module's providers array
bootstrap: [AppComponent]
})
export class AppModule { }
import the NativeNotificationService in your app’s component and inject it into your app’s constructor
import { Component } from '@angular/core';
import { NativeNotificationService } from 'angular-notice'; // import within component
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
constructor(private _service: NativeNotificationService) {} // angular will inject the service here via dependency injection
}
call the .notify() method off of the service.
someMethodThatGetsCalledWithinComponent(){
const options = {
title: 'hello world',
body : 'this is a notification body',
dir: 'ltr',
icon: '../assets/ng-shield.png',
tag: 'notice',
closeDelay: 2000
};
this._service.notify(options);
}