An alerts service and directive for setting and displaying alert messages. The directive uses the Twitter Bootstrap Alert component.
bower install angular-alerts --save
- Inject
alerts
in to your app moduleangular.module('app', ['alerts']);
.
Create an AlertsFactory
object to add and clear messages...
var alerts = new AlertsFactory();
// Add some messages
alerts.add('Success message', 'success');
alerts.add('Info message', 'info');
alerts.add('Warning message', 'warning');
alerts.add('Danger message', 'danger');
// Clear the alerts
alerts.clear();
// Add the object to the scope so it can be passed to the directive.
scope.alerts = alerts;
// Create another alerts object
scope.otherAlerts = new AlertsFactory();
scope.otherAlerts.add('Other alert', 'info');
Use the alerts
directive to display the messages...
<div alerts="alerts"></div>
<div alerts="otherAlerts"></div>