• Stars
    star
    142
  • Rank 250,808 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Growl notifications for AngularJS

AngularJS Growl Notifications

Growl notifications for AngularJS

Build Status

Notifications logically belong inside the view layer of your application.

Most existing growl systems require you to add notifications using JavaScript inside your controller layer.

This very lightweight library (<2KB) allows you to declaratively create notifications using directives only, supporting both inline expressions and HTML.

Think Growl, but in AngularJS directives. Oh, and Bootstrap compatible too.

Official website

Quick start

Learn how to create Mac OS X like pop-up notifications in your AngularJS application.

STEP 1: Install the library

Download the code from GitHub or install it using bower:

$ bower install angular-growl-notifications

Load the library in your markup:

<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="angular-growl-notifications.js"></script>

Load the growlNotifications module in your AngularJS application:

angular.module('yourApp', ['growlNotifications']);

The library is now loaded in your AngularJS application.

STEP 2: Specify where you want to render the notifications

Before you can create notifications, you need to add the growl-notifications (plural) directive to your markup.

This directive allows you to control where the notifications are rendered in your DOM in case your application requires special behavior.

In most cases you should simply add it as the first element inside the body element:

<body>
  <growl-notifications></growl-notifications>

  ...
</body>

Check out the growl-notifications directive documentation for more information.

STEP 3: Create notifications

You can now use the growl-notification (singular) directive to create notifications anywhere in your application:

<!-- This notification will be shown when the page loads -->
<growl-notification>
  Hello world
</growl-notification>

You can use AngularJS expressions:

<!-- This notification will be shown when the page loads -->
<growl-notification>
  Hello {{name}}
</growl-notification>

and HTML:

<!-- This notification will be shown when the page loads -->
<growl-notification>
  Hello <strong>{{name}}</strong>
</growl-notification>

Most of the time you will want to show a notification when some event occurs. You can use the native AngularJS ng-if directive to make this happen:

<!-- This notification will be shown when showNotification becomes truthy -->
<growl-notification ng-if="showNotification">
  showNotification just became truthy
</growl-notification>

By default notifications are shown for 5 seconds, but you can specify the ttl in milliseconds for every notification individually:

<growl-notification ttl="1000">
  Only show me for 1000ms
</growl-notification>

A ttl of -1 or false will disable the automatic closing timeout, making the notification permanent. You will need to close the notification manually using $growlNotification.remove().

You can also specify handlers you wish to run when the notification opens and closes:

<growl-notification on-open="doSomething()" on-close="doSomethingElse()">
  ...
</growl-notification>

which is convenient if you want to auto-reset some state when the notification is closed:

<button ng-click="showNotification = true">Show notification</button>

<!-- reset showNotification to false again when notification is closed -->
<!-- so the ng-if is triggered every time the button is clicked -->
<growl-notification ng-if="showNotification" on-close="showNotification = false">
  ...
</growl-notification>

Check out the growl-notification directive documentation for all available options.

STEP 4: Customize look and feel

By default no styling is applied so you can completely control the look and feel of the notifications in your application's stylesheet.

The possibilities are endless, for example to display notifications in the top right of your page:

growl-notifications{
  position: fixed;
  top: 150px;
  right: 10px;
}
growl-notification{
  border: 1px solid black;
  padding: 15px 30px;
  margin-bottom: 15px;
}

That's it

Hello world

You now have a working notification system in your AngularJS application.

When you load the page, a "Hello world" notification will automatically appear and disappear.

There are many additional features and options, so make sure to visit the examples page for more inspiration and sample code.

Manually closing notification after a UI-Router state change

If you find yourself in a rare situation where you need to manually close a notification after a state change, you can create a custom directive as demonstrated in this plunk and discussed in this thread.

License

MIT

Change log

v2.5.1

  • Added support for permanent notifications. Setting ttl to -1 or false will keep notifications visible until manually closed (e.g with $growlNotification.remove());

v2.6.0

  • Add support for infinite notification (#31)

v2.5.0

  • Replace $timeout with $interval to fix #28

v2.4.0

  • Updated timeout cancel mechanism (#27)

v2.3.0

  • Updated angular dependency version (#22)

v2.2.0

  • Added support for on-open handler
  • Added support for on-close handler
  • Updated documentation

v2.1.2

  • Make angular dependency version less strict

v2.1.1

  • Fix issue with injection of $animate in controller of growlNotification directive

v2.1.0

v2.0.1

  • Fix issue with minification of controller in growlNotification directive (see this issue).

v2.0.0

  • Directives have been rewritten for better performance
  • Now supports manually closing notifications using markup
  • v1 release has been moved to v1.x.x branch

v0.7.0

  • Added support for custom css prefix (defaults to Bootstrap alert)

v0.6.0

  • The growl-notifications directive now uses an isolate scope

v0.5.0

  • Added support for custom options in growl-notification directive
  • Updated demo page

v0.4.0

  • Added $animate support
  • Updated demo page

v0.3.0

  • Added dist directory with pre-built library files
  • Added demo page

v0.2.0

  • Added growl-notification directive to conveniently add notifications from within HTML markup
  • Added growl-notifications directive to conveniently display notifications from within HTML markup
  • Added documentation

v0.1.0

  • Initial version

More Repositories

1

generator-angular2-library

Yeoman generator to create an Angular library
JavaScript
750
star
2

github-scrum-workflow

Collection of scrum labels to apply agile tactics to a GitHub repository
247
star
3

copy-github-labels-cli

CLI tool to copy GitHub labels from one repository to another
JavaScript
154
star
4

angular-update-meta

Dynamically update meta tags for SEO purposes in your AngularJS application. Supports prerender.io.
JavaScript
135
star
5

generator-angularjs-library

A generator for Yeoman to generate the boilerplate for creating an AngularJS library
JavaScript
117
star
6

copy-github-labels

Easily copy labels from one GitHub repository to another
JavaScript
84
star
7

angular-contentful

Angular module to access the Contentful content delivery API
JavaScript
82
star
8

angular-environment-variables-demo

How to use environment variables to configure your Angular application without a rebuild
TypeScript
47
star
9

contentful-webhook-server

Contentful webhook server is a lightweight server to handle Contentful webhook HTTP requests
JavaScript
35
star
10

angularcodereview-com

Collection of free checklists you can use to perform a code review of your Angular application.
HTML
26
star
11

angular-consent

Easily show consent messages that keep appearing until the user clicks them away.
JavaScript
24
star
12

angular-http-decelerator

A lightweight HTTP interceptor for AngularJS to slow down HTTP responses
JavaScript
21
star
13

angularjs-google-maps

AngularJS library for working with Google Maps
JavaScript
20
star
14

contentful-agent

Node.js module to fetch entries from Contentful
JavaScript
13
star
15

angular2-todo-app

Angular 2 Todo Application
TypeScript
13
star
16

generator-jabl

A generator for Yeoman to build a website with Jade, AngularJS, Bootstrap and LESS
JavaScript
12
star
17

generator-php-library

A generator for Yeoman to generate boilerplate for a PHP library with support for PHPUnit
JavaScript
10
star
18

Ogone

PHP Classes for working with Ogone payment services
PHP
9
star
19

angular-user-settings

Easily manage persistent user settings in your AngularJS application
JavaScript
6
star
20

hb-bootstrap

Harp Boilerplate of a Bootstrap website
CSS
6
star
21

angular-embed-codepen

Easily embed codepen pens in your AngularJS application. No coding or custom markup required!
JavaScript
6
star
22

awesome-badge

Web component to display awesome badge that links to Sindre Sorhus' awesome list
HTML
5
star
23

angular-filter-pack

AngularJS Filter Pack
JavaScript
4
star
24

zf2-event-logger

Zend Framework 2 module that logs all events to the error_log.
PHP
4
star
25

ZendService_Oauth2

Oauth2 service for Zend Framework 2
PHP
3
star
26

web-application-performance-optimization

Checklist for optimizing web application performance
2
star
27

deploy-harp-to-gh-pages-using-travis

JavaScript
2
star
28

todo-app

Angular Todo Application for SitePoint Article
TypeScript
1
star
29

copy-github-labels-test-destination

Test repository to try out copy GitHub labels
1
star
30

angularjs-directive-scope-inspector

A visual scope inspector for the different AngularJS directive scope settings
JavaScript
1
star