Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
angular-alert-me
Advanced tools
Simple but fancy and light module to help you create and manager notifications with Angular.
Download the module using npm:
npm install angular-alert-me
or download it from github.
Add the style and the script to your html page:
<link rel="stylesheet" type="text/css" href="angular-alert-me.css">
<script type="text/javascript" src="angular-alert-me.js"></script>
Add module name to your application dependencies:
angular.module('app', ['alert-me']);
That's it now you can inject anywhere in your app the AlertMe service in order to manage the notifications.
Let's start by creating a simple default notification using the create function, this method will return the message just created:
angular.module('app')
.controller('MainCtrl', function(AlertMe) {
AlertMe.create('a simple alert').then(function(message) {
console.log('Message created:', message);
});
});
You can use the create function in two ways:
The default alert class is default, (not so fantasy) but you can create a fully customized alert your custom classes and doing your own style.
var msg = {
content: 'a custom alert',
className: 'my-class'
}
AlertMe.create(msg);
You can override the module defaults settings using configure method inside the config function:
angular.module('app')
.config(function(AlertProvider) {
AlertProvider.configure({
className: 'success' // this will be the default class if nothing is passed,
onBeforeCreate: function(conf) {
// do some checks
}
})
})
But you can always set override the properties per message passing a object to the create method, like in this example:
var msg = {
content: 'another custom alert!',
className: 'different',
dismissOnClick: true, // by clicking it will dismiss the alert
onDismiss: myCallBack // the callback to run when the alert is dismissed
}
function myCallback() { ... }
AlertMe.create(msg);
You can also use html text as content for your alerts, but be sure to add the isTrustedHtml flag property to your settings or to the message you want to be threated as html, like so:
var msg = {
content: 'visit our <a href="#!">page</a> on github',
isTrustedHtml: true // this will threat the content as html text
}
Also you can specify to use the default interceptor to notify all the HTTP request and responses errors.
angular.module('app')
.config(function($httpProvider) {
$httpProvider.interceptors.push('alertInterceptor');
});
But you can always disable notifications for particular HTTP calls by setting the notifyError configuration option to false.
$http({url: '/api/something', notifyError: false});
$http.get('/api/something', {notifyError: false});
$http.post('/api/something', data, {notifyError: false});
Now you can also use the desktop notifications if supported by the browser, for now you must set it globally:
angular.module('app')
.config(function(AlertProvider) {
AlertProvider.configure({ desktop: true });
});
In the new version 1.1.0 the create method (and also info, success, warning, danger) returns a Promise so you need to change the code if you want to upgrade from previous versions.
To all the methods listed below you can pass both a string
or a object
.
These settings can be edited using the method configure of AlertMe service.
See the examples section for more details about them.
Set the max simultaneous notification number to 10:
// Set the max alert number to 10:
AlertMe.configure({
maxNum: 10
});
Show he dismiss button for all the alerts:
// Show he dismiss button for all the alerts:
AlertMe.configure({
dismissButton: true
});
Error message with status code and text (assuming exist error object)
// Error message with status code and text
AlertMe.create({
className: 'error',
title: error.status,
content: error.statusText
});
Do a fixed alert that can't be closed
// Do a fixed alert that can't be closed
AlertMe.create({
content: 'This is very important.',
dismissButton: false,
dismissOnClick: false,
dismissTimeout: false
});
FAQs
Simple but fancy and light module to help you create and manager notifications with Angular.
We found that angular-alert-me demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.