This article describes the implementation method of AngularJS global warning box. Share it for your reference, as follows:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="" rel="external nofollow" > <script src=""></script> <script src=""></script> <script src=""></script> <script src=""></script> <script type="text/javascript"> var myapp = ('myapp', ['ngAnimate']); ('msgController', ['$scope', 'notificationService', function($scope, notificationService) { $ = notificationService; $ = function() { ('success'); } }]); ('controller', ['$scope', 'notificationService', function($scope, notificationService) { $ = function() { ('info'); } }]); ('msgBox', function() { return { restrict : 'EA', scope : { content: '@', type: '@', }, templateUrl : '', link : function(scope, elem, attrs) { = function() { = ''; }; } }; }); ('notificationService', function($timeout, $rootScope) { return { content : '', type : '', success : function(content) { (content, 'success') }, info : function(content) { (content, 'info') }, warning : function(content) { (content, 'warning') }, danger : function(content) { (content, 'danger') }, tmpl : function(content, type) { = content; = type; var _self = this; $timeout(function() { _self.clear(); }, 5000); }, clear : function() { = ''; = ''; } }; }); </script> <style type="text/css"> .msg-box { z-index: 666; position: absolute; width: 100%; top: 5px; } .-enter { transition: 2s linear all; opacity: 0.3; } .-enter-active { opacity: 1; } .-leave { transition: 2s linear all; opacity: 1; } .-leave-active { opacity: 0; } </style> </head> <body ng-app="myapp" ng-controller="msgController"> <msg-box content="{{}}" type="{{}}" class="msg-box"> </msg-box> <h1>content</h1> <button type="button" class="btn btn-primary" ng-click="show()">success</button> <div ng-controller="controller"> <button type="button" class="btn btn-primary" ng-click="show()">info</button> </div> </body> </html>
<div class="alert alert-{{type || 'info'}} msg" role="alert" ng-if="content"> <button type="button" class="close" aria-label="Close" ng-click="close()"> <span aria-hidden="true">×</span> </button> {{content}} </div>
For more information about AngularJS, readers who are interested in view the topic of this site:Summary of AngularJS command operation skills》、《AngularJS Introduction and Advanced Tutorial"and"AngularJS MVC architecture summary》
I hope this article will be helpful to everyone's AngularJS programming.