70 | Demo
Flash message for AngularJS and Bootstrap.
71 |80 | Another Demo 101 |
104 |
106 | Install angular-flashAdd the following code to the <head> of your document.
107 |108 | <link type="text/css" rel="stylesheet" href="dist/angular-flash.min.css" /> 109 | // If you are using bootstrap v3 no need to include angular-flash.min.css 110 | <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 111 | <script src="dist/angular-flash.min.js"></script> 112 | // Do not include both angular-flash.js and angular-flash.min.js 113 |114 |
Add ngFlash dependency to your module
115 |116 | var myApp = angular.module("app", ["ngFlash"]);117 |
Include flash-message directive in your 118 | HTML.
119 |120 | <flash-message></flash-message>121 |
125 |
127 | ConfigureYou can configure angular-flash by two ways:
128 | 129 |Add attributes on the <flash-message> directive.
130 |131 | <flash-message 132 | duration="5000" 133 | show-close="true" 134 | on-dismiss="myCallback(flash)" 135 | ></flash-message> 136 | // 5000ms as the default duration to show flash message. 137 | // Show the close button (x on the right). 138 | // Call myCallback with flash dismissed as parameter when flash has been dismissed.139 | 140 |
Set configuration with flashProvider.
141 |142 | app.config((FlashProvider) => { 143 | FlashProvider.setTimeout(5000); 144 | FlashProvider.setShowClose(true); 145 | FlashProvider.setOnDismiss(myCallback); 146 | FlashProvider.setAutoDismiss(false); 147 | });148 | 149 |
150 |
152 | Use a custom templateBy default, angular-flash use the Bootstrap flash standard template, but you can set your own template.
153 | 154 |By giving it in the Js: use .setTemplate(...) with the template in parameter.
155 |156 | app.config((FlashProvider) => { 157 | FlashProvider.setTemplate(` 158 |161 | 162 |{{ flash.text }}159 | `); 160 | });
By giving it in the HTML: use .setTemplatePreset('transclude') with the template transcluded in the <flash-message> directive.
163 |164 | app.config((FlashProvider) => { 165 | FlashProvider.setTemplatePreset('transclude'); 166 | });167 |
168 | <flash-message> 169 | <div class="my-flash">{{ flash.text }}</div> 170 | </flash-message>171 |
175 |
177 | How to useInject the Flash factory in your controller
178 |179 | myApp.controller('demoCtrl', ['Flash', function(Flash) { 180 | $scope.successAlert = function () { 181 | var message = '<strong> Well done!</strong> You successfully read this important alert message.'; 182 | var id = Flash.create('success', message, 0, {class: 'custom-class', id: 'custom-id'}, true); 183 | // First argument (string) is the type of the flash alert. 184 | // Second argument (string) is the message displays in the flash alert (HTML is ok). 185 | // Third argument (number, optional) is the duration of showing the flash. 0 to not automatically hide flash (user needs to click the cross on top-right corner). 186 | // Fourth argument (object, optional) is the custom class and id to be added for the flash message created. 187 | // Fifth argument (boolean, optional) is the visibility of close button for this flash. 188 | // Returns the unique id of flash message that can be used to call Flash.dismiss(id); to dismiss the flash message. 189 | } 190 | }]);191 | 192 |
196 | Flash alert types
-
197 |
- success 198 |
- info 199 |
- warning 200 |
- danger 201 |
207 | Methods
208 | These methods are mostly for internal usage but can be used also from outside. 209 |
210 |211 | Flash.dismiss(1); 212 | // Dismiss the flash with id of 1. Id is not the index of flash but instead a value returned by Flash.create() 213 |214 |
215 | Flash.clear(); 216 | // Dismisses all flashes shown. 217 |218 |
223 | Bootstrap
Angular-flash is fully compatible with Twitter Bootstrap. It uses standard Bootstrap classes. If 224 | Bootstrap CSS is already included in your document there is no need to include angular-flash.css in your 225 | document.
226 |231 | ngAnimate
If you want to use animations, include ngAnimate module. You can then use regular Angular animation 232 | technique for applying your own transitions.
233 |234 | var myApp = angular.module("app", ["ngFlash", "ngAnimate"]); 235 |236 |
237 | .alert {...} 238 | .alert.ng-enter, .alert.ng-enter.ng-enter-active {...} 239 | .alert.ng-leave, .alert.ng-leave.ng-leave-active {...} 240 |241 |
245 | Edit on Codepen
See the Pen Flash message for AngularJS by Sachin choolur (@sachinchoolur) on CodePen. 249 |
250 | 251 |266 | Like angular-flash? You may also like
-
267 |
- LightGallery 268 |
- lightSlider 269 |
- Lada-angular 270 |