Giter Club home page Giter Club logo

angular-notification's Introduction

angular-notification

Build Status Dependency Status devDependency Status

Notification service for Angular using native HTML5 API.

notification example

Install

Using bower

bower install angular-notification

Using npm

npm install angular-notification

Usage

angular.module('controllers.notification', ['notification'])
.controller('NotificationCtrl', function ($notification) {
  $notification('New message', {
    body: 'You have a new message.'
  });
})

$notification(title, options)

Create a new notification, the signature is the same as the Web Notification API.

Angular-notification provides some sugar to the default API, the permission is requested automatically. There is some options in addition to that already present in the official API:

  • "delay": Specify a delay (in ms) after the notification is automatically closed. Default null.
  • "focusWindowOnClick": Focus the window when the notification is clicked (works only on Chrome, Firefox prevent this for security issue). Default true.
$notification('title', {
  body: 'message',
  dir: 'auto',
  lang: 'en',
  tag: 'my-tag',
  icon: '/my-icon.jpg',
  delay: 1000, // in ms
  focusWindowOnClick: true // focus the window on click
})

$notificationProvider.setOptions(options)

Set default options.

$notificationProvider.setOptions({icon: '/my-icon.jpg'});

notification.close()

Close the notification.

var notification = $notification('hello');
notification.close();

notification.$on(name, listener)

Listen an event on the notification. Using this method, the listener is automatically wrapped in an $apply().

The signature is the same as the angular $scope.$on signature, it returns the deregistration function.

Avalaible examples are 'click', 'show', 'close' and 'error'.

var notification = $notification('hello');
var deregister = notification.$on('click', function () {
  console.log('User has clicked.');
});

// Stop listening the event.
deregister();

$notification.requestPermission()

Request explicitly the permission to display notification, more info in the official API.

$notification.requestPermission()
.then(function (permission) {
  console.log(permission); // default, granted, denied
});

License

MIT

angular-notification's People

Contributors

davinkevin avatar gregberge avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.