Giter Club home page Giter Club logo

angular-growl-notifications's Introduction

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

angular-growl-notifications's People

Contributors

evangellion avatar jbender avatar jvandemo avatar sfount avatar tdg5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-growl-notifications's Issues

Possible Merging of two projects

Hello,

I'm currently developing the following project https://github.com/JanStevens/angular-growl-2 now it seems to me our projects have very similar goals. Almost all the features I support are also supported by your project.

The one big difference (except some optional settings), is handling of server sent notifications. I think we can also include this in this project.

Let me know if you are interested in merging the two projects.

Shows first time, then nomore

I'm trying to implement this directive into my admin panel.
But before I wanted to do any massive work with it I wanted to try it out first.
The result was - it only shows once then ignore every other time I click to make it appear.

Here's my code:

AngularController:

    $scope.growl = {
        message: '',
        messageType: '',
        showGrowl: false,

        setMessageType: function(type) {
            this.messageType = type;
        },
        getMessageType: function() {
            return this.messageType;
        },
        getMessage: function() {
            return this.message;
        },
        setMessage: function(message) {
            this.message = message;
        },
        reset: function() {
            this.message = '';
            this.messageType = '';
            this.showGrowl = false;
        }
    };

    $scope.successGrowlTest = function() {
        $scope.growl.showGrowl = true;
        $scope.growl.setMessageType('success');
        $scope.growl.setMessage('This is a success test message');
        $scope.growl.reset();

    };

    $scope.warningGrowlTest = function() {
        $scope.growl.showGrowl = true;
        $scope.growl.setMessageType('warning');
        $scope.growl.setMessage('This is a warning test message');
        $scope.growl.reset();
    };

    $scope.errorGrowlTest = function() {
        $scope.growl.showGrowl = true;
        $scope.growl.setMessageType('error');
        $scope.growl.setMessage('This is a error test message');
        $scope.growl.reset();
    };

I make my own growl-object to be able to set the notification data the way I want it (to be able to variate between different css-classes and so on.

View:

<body>
<growl-notifications class="growl"></growl-notifications>
    [...]
    <div class="well">
        <a ng-click="successGrowlTest()">Success test</a>
        <a ng-click="warningGrowlTest()">Warning test</a>
        <a ng-click="errorGrowlTest() ">Error test</a>
    </div>

    <growl-notification class="fading" ng-if="growl.showGrowl === true" ng-class="'bg-' + growl.getMessageType()" ttl="1000">
        {{growl.getMessage()}}
    </growl-notification>

App.js

var app = angular.module("app", ['ngRoute', 'ngAnimate', 'ngSanitize', 'ngResource', 'ngCookies', 'angular-flash.service', 'angular-flash.flash-alert-directive', 'gettext', 'ui.bootstrap', 'growlNotifications']);

Any clues?

on-close function gets called immediately

Hi,
I am trying to use angular-growl-notifications for notifications. I am having trouble using on-close handler.

Here is the code snippet, I use to include on-close function :
<div><growl-notification ng-if="error" class="alert alert-danger" ttl="50000" on-close="{{onClose()}}" > <strong>{{message}}</strong></growl-notification></d iv>

and in the controller :

var showErrorMessage = function(msg, $scope) {
$scope.message=JSON.stringify(msg);
$scope.error = 1;
$scope.onClose = function(){
console.log("Before error = "+$scope.error);
console.log("onClose called");
$scope.error = 0;
console.log("After error = "+$scope.error);
};

The on-close function gets called immediately multiple times. In addition, it also gets called after the ttl timeout happens. This makes the error flag go to 0 prematurely and not after the ttl timeout has happened, causing the message to not display at all.

Do you think, I am not using it correctly ? In the documentation, I didn't find anything different from what I am doing.

undefined is not a function when minified

This works great when running code in dev mode, but when I run grunt (ngmin, uglify, etc), I receive the following error: undefined is not a function.

I have removed all references to growlNotifications througout my code, with the exception of my main angular module. When I remove growlNotifications from the main module, everything works fine.
If I skip ngmin and just uglify, I get
Uncaught Error: [$injector:modulerr] Failed to instantiate module choiceAdminApp due to: Error: [$injector:unpr] Unknown provider: a
I glanced at your source code and did not see any obvious offenders.
Any tips on getting growlNotifications working when ngmined and uglified?

on-close not working

I tried to use the on-close hook, but no luck so far. Neither a function call or just a flag set as in the examples does not work. Has this been updated for angular versions 1.4.0 -> ???

License information missing

Hi,

I haven't found any license information for your project. I would love to use it for an app, but I need to state all licenses of 3rd party libs. Is the license available somewhere and I missed it, or is it missing?

Cheers,
Daniel

Cannot read property 'parent' of undefined

Hi, sorry to say but it doesn't work for me. I receive error like in title with simplest 'hello world' example.
I defined in the index.html following scripts:

<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script type="text/javascript" src="js/vendor/angular-growl-notifications.js"></script>
<script src="js/main.js"></script>

next, my body looks like this:

<body ng-app="myApp">
{{3+2}}
<growl-notifications>
    <growl-notification>hello world</growl-notification>
</growl-notifications>
</body>

and then main.js:

var myApp = angular.module("myApp", ['growlNotifications']);

Result below
image

What I am doing wrong?
br,

Notification lifecycle

After form submission, in my form view, I want to notify a given kind of error.
I'm forcing the error to always happen.
At first submission the notification happens. Then any further submission does not leverage a new notification.
Is this a expected behavior? If so, how am I supposed to handle it?

My markup:

<span ng-if="err1" growl-notification="{ type: 'danger' }">Foo</span>

growl notification ttl is not getting applied

Hi, when I use the following, the message "Loading growl-Notifications" is appearing on the screen. But then it is remaining their forever, even though I have given ttl=1000, the notification is not disappearing after 1000ms. Could you please let me know, what could be the reason?
Loading growl-Notifications

v2 dynamic notifications

Will these be making a come back?
The growlNotifications.add('some dynamic notification') methods?

We use these all the time

class="ng-scope" error in dev console

Getting this in the dev console:

Cannot read property 'parent' of undefined...
""

Any ideas?

My growl notification elements have a class on it and nothing else as attributes.

Render same notification multiple times

ng-if="success" not really easy to render the same notification multiple times :(

<growl-notification ng-if="success">
  Hello world
</growl-notification>

How should we do?
Thanks!

Error: after is undefined

Good afternoon.

I need help with this error that throws me, look in the documentation and did not find anything about a solution, I understand that after is optional "move (element, parent, [after], [options])", I also found a discussion on this error, but it shows nothing of a possible solution.

I will be very grateful if you help me, and sorry for my bad English

Thank you

Heytel

(Proposal) Replace $timeout with $interval (Accommodate Protractor tests)

As referenced in #27 there are some quirks with Angular's Protractor library waiting on the $timeout service. A full discission of this can be found here.

Proposal:
As mentioned in this comment Protractor does not need to wait on the $interval service and so end to end tests perform as standard.

Replace

// TTL = 5000
$timeout(function () { }, TTL) //...

with

// only run this interval once - replicating the functionality found in $timeout
var REPEATS  = 1;
$interval(function () {}, TTL, REPEATS) //...

I have verified that this change has no breaking implications, however there may be something I've missed. If this is discussed and approved it can be easily implemented.

Inline HTML

Inline HTML does not seem to work when I add notification dynamically, is there a config I need to enable?

image

Cannot read property 'parent' of undefined

Hi I'm receiving the following error : Cannot Read property of 'parent' of undefined.

My HTML :

 <div class="notificationHolder">
        <div ng-repeat="(iid, notification) in notifications track by notification.iid" class="animNotifcation">



                <growl-notification ttl="5000">
                    <span ng-bind-html="notification.message"></span>
                </growl-notification>
            </div>
        </div>
    </div>

My Test event :

$scope.$on("notification", function (event, args) {
            index++;
            args.notification.iid = index;
            args.notification.message += " " + index;
            $scope.notifications.push(args.notification);
            $timeout(function () {
                $scope.notifications.shift();
                //$scope.notifications.splice(index, 1);
            }, 5000);
        });

When I've de-bugged it in google chrome - I located the following line in the link function :
$animate.move(iElem, growlNotifications.element);

and growlNotifications.element is undefined.

I'm using Angular 1.5 with jquery 2.2.4 if that makes a difference.

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.