# angular-notification

> Notification service for Angular using native HTML5 API.

Latest version **1.1.1** (published 2015-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install angular-notification
pnpm add angular-notification
yarn add angular-notification
bun add angular-notification
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2015-06-12 |
| First published | 2015-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 91 |
| Author | Greg Bergé |
| Maintainers | neoziro |
| Keywords | angular, notification, service |

## Links

- npm: https://www.npmjs.com/package/angular-notification
- Repository: https://github.com/neoziro/angular-notification
- Issues: https://github.com/neoziro/angular-notification/issues
- npm.io page: https://npm.io/package/angular-notification

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2015-06-12
- 1.1.0 — 2015-06-10
- 1.0.1 — 2015-03-24
- 1.0.0 — 2015-03-20

## README

# angular-notification

[![Build Status](https://travis-ci.org/neoziro/angular-notification.svg?branch=master)](https://travis-ci.org/neoziro/angular-notification)
[![Dependency Status](https://david-dm.org/neoziro/angular-notification.svg?theme=shields.io)](https://david-dm.org/neoziro/angular-notification)
[![devDependency Status](https://david-dm.org/neoziro/angular-notification/dev-status.svg?theme=shields.io)](https://david-dm.org/neoziro/angular-notification#info=devDependencies)

Notification service for Angular using native HTML5 API.

![notification example](https://f.cloud.github.com/assets/266302/2423762/a38113ac-ab9e-11e3-8e8a-2e4fe299e9f5.png)

## Install

### Using bower

```
bower install angular-notification
```

### Using npm

```
npm install angular-notification
```

## Usage

```js
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](https://developer.mozilla.org/en/docs/Web/API/notification).

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`.

```js
$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.

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

### notification.close()

Close the notification.

```js
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'.

```js
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](https://developer.mozilla.org/en-US/docs/Web/API/Notification.requestPermission).

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

## License

MIT

---
_Source: https://npm.io/package/angular-notification · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
