AngularJS全局警告框?qū)崿F(xiàn)方法示例
本文實(shí)例講述了AngularJS全局警告框?qū)崿F(xiàn)方法。分享給大家供大家參考,具體如下:
<!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="bootstrap.min.css" rel="external nofollow" >
<script src="jquery.min.js"></script>
<script src="angular.js"></script>
<script src="angular-animate.js"></script>
<script src="bootstrap.min.js"></script>
<script type="text/javascript">
var myapp = angular.module('myapp', ['ngAnimate']);
myapp.controller('msgController', ['$scope', 'notificationService', function($scope, notificationService) {
$scope.msg = notificationService;
$scope.show = function() {
notificationService.danger('success');
}
}]);
myapp.controller('controller', ['$scope', 'notificationService', function($scope, notificationService) {
$scope.show = function() {
notificationService.info('info');
}
}]);
myapp.directive('msgBox', function() {
return {
restrict : 'EA',
scope : {
content: '@',
type: '@',
},
templateUrl : 'tmpl.html',
link : function(scope, elem, attrs) {
scope.close = function() {
scope.content = '';
};
}
};
});
myapp.factory('notificationService', function($timeout, $rootScope) {
return {
content : '',
type : '',
success : function(content) {
this.tmpl(content, 'success')
},
info : function(content) {
this.tmpl(content, 'info')
},
warning : function(content) {
this.tmpl(content, 'warning')
},
danger : function(content) {
this.tmpl(content, 'danger')
},
tmpl : function(content, type) {
this.content = content;
this.type = type;
var _self = this;
$timeout(function() {
_self.clear();
}, 5000);
},
clear : function() {
this.content = '';
this.type = '';
}
};
});
</script>
<style type="text/css">
.msg-box {
z-index: 666;
position: absolute;
width: 100%;
top: 5px;
}
.msg.ng-enter {
transition: 2s linear all;
opacity: 0.3;
}
.msg.ng-enter-active {
opacity: 1;
}
.msg.ng-leave {
transition: 2s linear all;
opacity: 1;
}
.msg.ng-leave-active {
opacity: 0;
}
</style>
</head>
<body ng-app="myapp" ng-controller="msgController">
<msg-box content="{{msg.content}}" type="{{msg.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>
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進(jìn)階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對(duì)大家AngularJS程序設(shè)計(jì)有所幫助。
- AngularJS動(dòng)態(tài)菜單操作指令
- angularjs+bootstrap菜單的使用示例代碼
- AngularJS實(shí)現(xiàn)樹形結(jié)構(gòu)(ztree)菜單示例代碼
- 實(shí)例詳解AngularJS實(shí)現(xiàn)無限級(jí)聯(lián)動(dòng)菜單
- AngularJS自定義指令之復(fù)制指令實(shí)現(xiàn)方法
- AngularJS使用ng-class動(dòng)態(tài)增減class樣式的方法示例
- AngularJS實(shí)現(xiàn)動(dòng)態(tài)添加Option的方法
- AngularJS+bootstrap實(shí)現(xiàn)動(dòng)態(tài)選擇商品功能示例
- AngularJS自定義指令實(shí)現(xiàn)面包屑功能完整實(shí)例
- AngularJS使用攔截器實(shí)現(xiàn)的loading功能完整實(shí)例
- AngularJS折疊菜單實(shí)現(xiàn)方法示例
相關(guān)文章
AngularJS基礎(chǔ) ng-class-odd 指令示例
本文主要介紹AngularJS ng-class-odd 指令,這里對(duì)ng-class-odd基礎(chǔ)知識(shí)做了詳細(xì)整理,并有示例代碼和效果圖,學(xué)習(xí)AngularJS的同學(xué)可以參考下2016-08-08
AngularJS入門教程之路由機(jī)制ngRoute實(shí)例分析
這篇文章主要介紹了AngularJS入門教程之路由機(jī)制ngRoute,結(jié)合實(shí)例形式分析了AngularJS路由機(jī)制的原理、ngRoute的組成、配置、參數(shù)與相關(guān)使用技巧,需要的朋友可以參考下2016-12-12
angularjs使用directive實(shí)現(xiàn)分頁組件的示例
本篇文章主要介紹了angularjs使用directive實(shí)現(xiàn)分頁組件的示例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-02-02
AngularJS基礎(chǔ) ng-include 指令示例講解
本文主要介紹AngularJS ng-include 指令,這里對(duì)ng-include 指令的知識(shí)做了詳細(xì)整理介紹,有需要的朋友可以參考下2016-08-08
AngularJS學(xué)習(xí)筆記之ng-options指令
ng-options是angular-1.3新出的一個(gè)指令,這篇文章就來介紹這個(gè)指令的用法.有需要的小伙伴可以參考下。2015-06-06
AngularJS折疊菜單實(shí)現(xiàn)方法示例
這篇文章主要介紹了AngularJS折疊菜單實(shí)現(xiàn)方法,結(jié)合完整實(shí)例形式分析了AngularJS實(shí)現(xiàn)折疊菜單的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-05-05
AngularJs 國(guó)際化(I18n/L10n)詳解
本文主要介紹AngularJs 國(guó)際化的知識(shí),這里整理了詳細(xì)的資料來講解國(guó)際化,有需要的小伙伴可以參考下2016-09-09

