Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Minimalistic and extensible notification service for Angular.

License

NotificationsYou must be signed in to change notification settings

cgross/angular-notify

Repository files navigation

#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 --savenpm install @cgross/angular-notify`

Adddist/angular-notify.js anddist/angular-notify.css to your index.html.

AddcgNotify as a module dependency for your module.

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

Then inject and use thenotify service.

functionmyController($scope,notify){// <-- Inject notifynotify('Your notification message');// <-- Call notify with your messagenotify({message:'My message',templateUrl:'my_template.html'});}

Options

notify(String|Object)

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

  • message - Required. The message to show.
  • duration - Optional. The duration (in milliseconds) of message. A duration of 0 will prevent messages from closing automatically.
  • templateUrl - Optional. A custom template for the UI of the message.
  • classes - Optional. A list of custom CSS classes to apply to the message element.
  • messageTemplate - Optional. A string containing any valid Angular HTML which will be shown instead of the regularmessage text. The string must contain one root element like all valid Angular HTML templates (so wrap everything in a<span>).
  • scope - Optional. A valid Angular scope object. The scope of the template will be created by calling$new() on this scope.
  • position - Optional.center,left andright are the only acceptable values.
  • container - Optional. Element that contains each notification. Defaults todocument.body.

This function will return an object with aclose() method and amessage property.

notify.config(Object)

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

  • duration - The default duration (in milliseconds) of each message. A duration of 0 will prevent messages from closing automatically.
  • startTop - The Y pixel value where messages will be shown.
  • verticalSpacing - The number of pixels that should be reserved between messages vertically.
  • templateUrl - The default message template.
  • position - The default position of each message.center,left andright are the supported values.
  • container - The default element that contains each notification. Defaults todocument.body.
  • maximumOpen - The maximum number of total notifications that can be visible at one time. Older notifications will be closed when the maximum is reached.

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 useng-controller="YourCtrl").

The scope for the partial will either be descended from$rootScope or the scope specified in thenotify({...}) 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.

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

Release History

  • v2.5.1 - 01/05/2017
    • Fixed for Angular 1.6 promise method changes.
    • Published to NPM.
  • v2.5.0 - 04/12/2015
    • Newduration property per notification.
    • Newposition property per notification.
    • Fix for DOM elements not being removed.
    • NewmaximumOpen config option.
    • Bump Angular dependency to 1.3.
  • v2.0.2 - 09/06/2014
    • Default template redesigned with a Bootstrap look and feel. Default template now also includes a close button.
    • Default message location is now the top center.
    • Default message duration is now 10 seconds.
    • Default verticalSpacing is now 15px.
    • Thetemplate option was renamed totemplateUrl.
    • NewmessageTemplate option added.
    • Newclasses option added.
    • Fixed an issue causing a message with multiple lines of text to be placed into the visible area too soon.
    • Fixed #4 (config() not correctly setting startTop)
  • v1.1.0 - 5/18/2014 - Added return value allowing for closing and updating of message.
  • v1.0.0 - 4/16/2014 - Significant refactoring.
  • JQuery is no longer a required dependency.
  • [Breaking Change] Configure the default template usingconfig() now instead of thecgNotifyTemplate value.
  • [Breaking Change] TheverticalSpacing parameter should no longer include the height of the notification element.
  • [Breaking Change] Thescope options must now be a valid Angular scope.
  • [Breaking Change] The duration of the notifications is now based on aduration config property and does not rely on the delay attribute of the CSS transition.
  • Messages can now word wrap if you use amax-width css value.
  • The scope for templates now includes a$close() function.
  • Newnotify.closeAll() method.
  • v0.2.0 - Adding custom templates ability, fixed FF bug.
  • v0.1.0 - Initial release.

[8]ページ先頭

©2009-2025 Movatter.jp