Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Web Notifications AngularJS Service

License

NotificationsYou must be signed in to change notification settings

sagiegurari/angular-web-notification

Repository files navigation

NPM VersionCICoverage StatusKnown VulnerabilitiesInline docsLicense

Web Notifications AngularJS Service

Overview

The angular-web-notification is an angular service wrapper for the web notifications API.

It is using thesimple-web-notification library which provides a simple and easy notification API which works across browsers and provides automatic permission handling.

SeeW3 Specification andsimple-web-notification for more information.

Angular 2 and Up

For angular 2 and above, it is recommanded to use thesimple-web-notification library directly.
It provides the same API and it is not dependend on angular.

Demo

Live Demo

Usage

In order to use the angular service you first must add the relevant dependencies:

<scripttype="text/javascript"src="angular.js"></script><scripttype="text/javascript"src="simple-web-notification/web-notification.js"></script><scripttype="text/javascript"src="angular-web-notification.js"></script>

Next you must define it as a dependency in your main angular module as follows:

angular.module('exampleApp',['angular-web-notification']);

Now you can inject and use the service into your modules (directives/services/...), for example:

angular.module('exampleApp').directive('showButton',['webNotification',function(webNotification){return{    ...link:function(scope,element){element.on('click',functiononClick(){webNotification.showNotification('Example Notification',{body:'Notification Text...',icon:'my-icon.ico',onClick:functiononNotificationClicked(){console.log('Notification clicked.');},autoClose:4000//auto close the notification after 4 seconds (you can manually close it via hide function)},functiononShow(error,hide){if(error){window.alert('Unable to show notification: '+error.message);}else{console.log('Notification Shown.');setTimeout(functionhideNotification(){console.log('Hiding notification....');hide();//manually close the notification (you can skip this if you use the autoClose option)},5000);}});});}};}]);

In case you wish to use service worker web notifications, you must provide the serviceWorkerRegistration in the options as follows:

//Get the service worker registeration object at the startup of the application.//This is an aysnc operation so you should not try to use it before the promise is finished.varserviceWorkerRegistration;navigator.serviceWorker.register('service-worker.js').then(function(registration){serviceWorkerRegistration=registration;});//when setting on even handlers in different areas of the application, use that registration object instance (must be done after the registration is available)element.on('click',functiononClick(){webNotification.showNotification('Example Notification',{serviceWorkerRegistration:serviceWorkerRegistration,body:'Notification Text...',icon:'my-icon.ico',actions:[{action:'Start',title:'Start'},{action:'Stop',title:'Stop'}],autoClose:4000//auto close the notification after 4 seconds (you can manually close it via hide function)},functiononShow(error,hide){if(error){window.alert('Unable to show notification: '+error.message);}else{console.log('Notification Shown.');setTimeout(functionhideNotification(){console.log('Hiding notification....');hide();//manually close the notification (you can skip this if you use the autoClose option)},5000);}});});

Installation

Run npm install in your project as follows:

npm install --save angular-web-notification

Or if you are using bower, you can install it as follows:

bower install angular-web-notification --save

Limitations

The web notifications API is not fully supported in all browsers.

Please seesupported browser versions for more information on the official spec support.

API Documentation

See full docs at:API Docs

Contributing

Seecontributing guide

Release History

DateVersionDescription
2020-05-13v2.0.1Revert bower.json deletion but not use it in CI build
2020-05-11v2.0.0Migrate to github actions, upgrade minimal node version and remove bower
2019-02-08v1.2.31Maintenance
2017-08-25v1.2.24Document support of service worker web notifications
2017-01-22v1.2.0Split the internal web notification API into a new project: simple-web-notification
2016-11-23v1.0.19Use forked version of html5-desktop-notifications in order to resolve few issues
2016-11-04v1.0.16Upgrading to html5-desktop-notifications 3.0.0
2016-09-10v1.0.6Default to website favicon.ico if icon not provided in options
2016-09-07v1.0.4Callback is now optional
2016-06-14v0.0.78Published via NPM (in addition to bower)
2016-03-08v0.0.65Added webNotification.permissionGranted attribute
2015-09-26v0.0.31Update bower dependencies
2015-09-26v0.0.30Added 'onClick' option to enable adding onclick event handler for the notification
2015-08-16v0.0.22uglify fix
2015-02-16v0.0.7Automatic unit tests via karma
2015-02-05v0.0.5Doc changes
2014-12-09v0.0.3API now enables/disables the capability to automatically request for permissions needed to display the notification.
2014-12-08v0.0.2Initial release

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

About

Web Notifications AngularJS Service

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp