
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
ng-push-ivy
Advanced tools
Angular Push Notifications API Wrapper
If you aren't familiar with push notifications you can read more about them on the Mozilla developer network.
To install this library, run:
$ npm install ng-push-ivy --save
Import the PushNotificationsModule
in to your AppModule
:
@NgModule({
imports: [PushNotificationsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
Now import the PushNotificationsService
where you want to use it:
constructor( private _pushNotifications: PushNotificationsService ) {}
To request permission from the user to display push notifications call the requestPermission()
method on the PushNotificationsService
.
You can create a notification calling the create(title: string, options: PushNotification)
method, like this:
this._pushNotifications.create('Test', {body: 'something'}).subscribe(
res => console.log(res),
err => console.log(err)
)
The create()
method returns an observable that emits the notification and the event when ever a show, click, close or error event occurs.
If you don't have permission to display the notification then the Permission not granted
error will be thrown.
The following are options that can be passed to the options parameter:
interface PushNotification {
body?: string
icon?: string
tag?: string
renotify?: boolean
silent?: boolean
sound?: string
noscreen?: boolean
sticky?: boolean
dir?: 'auto' | 'ltr' | 'rtl'
lang?: string
vibrate?: number[]
}
Options correspond to the Notification interface of the Notification API: Mozilla developer network.
this._pushNotifications.create(
'Example One',
{body: 'Just an example'}
)
.subscribe(res => {
if (res.event.type === 'click') {
// You can do anything else here
res.notification.close();
}
}
)
Thank you @anode7 for submitting this example
import {Component, Inject, PLATFORM_ID, Injector} from '@angular/core';
import {isPlatformBrowser} from '@angular/common';
@Component({})
export class ExampleComponent {
private _push:PushNotificationsService;
constructor(
@Inject(PLATFORM_ID) platformId: string,
private injector: Injector,
) {
if (isPlatformBrowser(platformId)) {
//inject service only on browser platform
this._push = this.injector.get(PushNotificationsService);
}
}
}
A standard method used in Universal is creating a mock service which is injected in the ServerModule
. A good example can be found here.
$ npm run build
MIT © JerryFZhang
FAQs
Angular Push Notifications API Wrapper
The npm package ng-push-ivy receives a total of 683 weekly downloads. As such, ng-push-ivy popularity was classified as not popular.
We found that ng-push-ivy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.