今天就跟大家聊聊有關(guān)使用AngularJS怎么實(shí)現(xiàn)一個(gè)全局警告框,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

具體如下:
<!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>
<h2>content</h2>
<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>看完上述內(nèi)容,你們對(duì)使用AngularJS怎么實(shí)現(xiàn)一個(gè)全局警告框有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝大家的支持。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前文章:使用AngularJS怎么實(shí)現(xiàn)一個(gè)全局警告框-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://chinadenli.net/article48/pesep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、域名注冊(cè)、網(wǎng)站建設(shè)、網(wǎng)站改版、ChatGPT、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容