Angular.js, Animate.css, Glyphicons, based component for stylish and flexible application notifications.
Web applications requires notify users of ongoing events. Common cases are errors, successful completion notifications etc. With ng-notifications-bar
it's as easy as,
<body>
<notifications-bar class="notifications"></notifications-bar>
...
Npm installation,
$ npm install ng-notifications-bar --save
Or bower installation,
$ bower install ng-notifications-bar --save
Update your scripts and styles section or use the require for browserified applications.
<link rel="stylesheet" href="bower_components/ng-notifications-bar/dist/ngNotificationsBar.min.css" />
<script scr="bower_components/angular-notifications-bar/dist/ng-notifications-bar.min.js"></script>
For browserify
applications, require module in yours application module,
require('ng-notifications-bar');
In case you are using sass
in project, it's possible to just import ngNotificationsBar
styles,
@import "../../node_modules/ng-notifications-bar/sass/ngNotificationsBar";
In application module,
angular.module('app', ['ngNotificationsBar']);
Please note, since ng-notifications-bar
have a dependency on glyphicons
you have to copy /fonts
folder into yours /public
folder manually.
The module consists of there elements - directive, service and provider.
notifications-bar
element directive, should be placed once, typically right after <body>
open tag.
<notifications-bar class="notifications"></notifications-bar>
Possible to use as attribute, as well
<div notifications-bar class="notifications"></div notifications-bar>
notification
service is used by controllers (or other directives), to show notifications.
app.controllers('app', function ($scope, api, notifications) {
api.get({resource: 'tasks'})
.then(function (tasks) {
$scope.tasks = tasks;
}, function (error) {
notifications.showError({message: error.message});
});
$scope.submitTask = function () {
api.post({resource: 'tasks'}, {description: this.description})
.then(function () {
notifications.showSuccess({message: 'Your task posted successfully'});
}, function (error) {
notifications.showError({message: 'Oh no! Task submission failed, please try again.'});
});
}
});
notificationsConfigProvider
is used to override some notifications bar defaults.
app.config(['notificationsConfigProvider'], function (notificationsConfigProvider) {
// auto hide
notificationsConfigProvider.setAutoHide(true)
// delay before hide
notificationsConfigProvider.setHideDelay(3000)
}])
It is possible to setup the whole notifications bar module in module config and each notification separately in controller
Available options:
- autoHide
- hideDelay
app.config(['notificationsConfigProvider'], function (notificationsConfigProvider) {
// auto hide
notificationsConfigProvider.setAutoHide(true);
// delay before hide
notificationsConfigProvider.setHideDelay(3000);
}])
app.controller('main', function ($scope, notifications) {
$scope.showError = function () {
notifications.showError({
message: 'Oops! Something bad just happened! (hides faster)',
hideDelay: 1500, //ms
hide: true //bool
});
};
});
Install bower
dependencies,
$ bower install
Install npm
dependencies,
$ npm install
Run grunt
build,
$ grunt
as result, /dist
folder is created with ready to use .js
and .css
file.
Project doesn't have tests at the moment, so run example
and check the functionality,
$ grunt start:example
Copyright (c) 2014, [email protected]
MIT