Demo
Flash message for AngularJS and Bootstrap.
How to use angular-flash?
Add the following code to the <head> of your document.
<link type="text/css" rel="stylesheet" href="dist/angular-flash.min.css" /> // If you are using bootstrap v3 no need to include angular-flash.min.css <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="dist/angular-flash.min.js"></script> // Do not include both angular-flash.js and angular-flash.min.js
Add ngFlash dependency to your module
var myApp = angular.module("app", ["ngFlash"]);
Include flash-message directive in your HTML.
<flash-message duration="5000"></flash-message> // 5000ms as the default duration to show flash message.
Inject the Flash factory in your controller
myApp.controller('demoCtrl', ['Flash', function(Flash) { $scope.successAlert = function () { var message = '<strong> Well done!</strong> You successfully read this important alert message.'; Flash.create('success', message, 0, 'custom-class'); // First argument is the type of the flash alert // Second argument is the message displays in the flash alert (HTML ok) // Third argument (optional) is the duration of showing the flash. 0 to not automatically hide flash (user needs to click the cross on top-right corner). // Fourth argument (optional) is the custom class to be added for the flash message created } }]);
Flash alert types
- success
- info
- warning
- danger
Methods
These methods are mostly for internal usage but can be used also from outside.
Flash.pause(4); // Pause the fifth flash' auto dismiss. Flash.dismiss(1); // Dismiss the second flash shown
Bootstrap
Angular-flash is fully compatible with Twitter Bootstrap. It uses standard Bootstrap classes. If Bootstrap CSS is already included in your document there is no need to include angular-flash.css in your document.
ngAnimate
If you want to use animations, include ngAnimate module. You can then use in-built classes .alertIn and .alertOut for applying CSS.
var myApp = angular.module("app", ["ngFlash", "ngAnimate"]);
.alertIn, .alertOut {...} .alertIn.ng-hide-remove, .alertOut.ng-hide-add.ng-hide-add-active {...} .alertOut.ng-hide-add, .alertIn.ng-hide-remove.ng-hide-remove-active {...}
Edit on Codepen
See the Pen Flash message for AngularJS by Sachin choolur (@sachinchoolur) on CodePen.