cgross / angular-notify

Minimalistic and extensible notification service for Angular.
http://cgross.github.io/angular-notify/demo/
MIT License
432 stars 99 forks source link

angular-notify

A minimalistic (and extensible) notification service for Angular.

Live Demo

Supports IE 10, and recent versions of FF and Chrome.

Getting Started

Install with Bower, npm, or download the the files directly from the dist folder in the repo.

bower install angular-notify --save
npm install @cgross/angular-notify`

Add dist/angular-notify.js and dist/angular-notify.css to your index.html.

Add cgNotify as a module dependency for your module.

angular.module('your_app', ['cgNotify']);

Then inject and use the notify service.

function myController($scope,notify){  // <-- Inject notify

  notify('Your notification message'); // <-- Call notify with your message

  notify({ message:'My message', templateUrl:'my_template.html'} );

}

Options

notify(String|Object)

The notify function can either be passed a string or an object. When passing an object, the object parameters can be:

This function will return an object with a close() method and a message property.

notify.config(Object)

Call config to set the default configuration options for angular-notify. The following options may be specified in the given object:

notify.closeAll()

Closes all currently open notifications.

Providing Custom Templates

Angular-notify comes with a very simplistic default notification template. You are encouraged to create your own template and style it appropriate to your application. Templates can also contain more advanced features like buttons or links. The message templates are full Angular partials that have a scope (and a controller if you use ng-controller="YourCtrl").

The scope for the partial will either be descended from $rootScope or the scope specified in the notify({...}) options. The template scope will be augmented with a $message property, a $classes property, and a special $close() function that you may use to close the notification.

The messageTemplate property is also included on the scope as $messageTemplate. To ensure your custom template works with the messageTemplate option, your template should hide the normal text if $messageTemplate contains a value, and should have an element with the cg-notify-message-template class. The element with the cg-notify-message-template class will have the compiled template appended to it automatically.

Release History