Skip to content

wrenth04/angular-web-notification

 
 

Repository files navigation

angular-web-notification

Bower Version Build Status Coverage Status Code Climate bitHound Score Inline docs License

Web Notifications AngularJS Service

Overview

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

It is using the HTML5-Desktop-Notifications library which provides a unified API for all browsers.

See W3 Specification and HTML5-Desktop-Notifications for more information.

Demo

Live Demo at Plunker

Usage

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

<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="HTML5-Desktop-Notifications/desktop-notify.js"></script>
<script type="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', function onClick() {
            webNotification.showNotification('Example Notification', {
                body: 'Notification Text...',
                icon: 'my-icon.ico'
            }, function onShow(error, hide) {
                if (error) {
                    window.alert('Unable to show notification: ' + error.message);
                } else {
                    console.log('Notification Shown.');

                    setTimeout(function hideNotification() {
                        console.log('Hiding notification....');
                        hide();
                    }, 5000);
                }
            });
        });
    }
};
}]);

Installation

Run bower install in your project as follows:

bower install angular-web-notification --save

Limitations

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

Please see http://caniuse.com/#feat=notifications for more information on the official spec support and at HTML5-Desktop-Notifications for more browser specific API support.

API Documentation

See full docs at: API Docs

Release History

Date Version Description
2015-06-24 v0.0.20 Maintenance
2015-02-16 v0.0.7 Automatic unit tests via karma
2015-02-05 v0.0.5 Doc changes
2014-12-30 v0.0.4 Doc changes
2014-12-09 v0.0.3 API now enables/disables the
capability to automatically request for
permissions needed to display the notification.
2014-12-08 v0.0.2 Initial release

License

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

About

Web Notifications AngularJS Service

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 93.8%
  • HTML 6.2%