詳解AngularJS 模態(tài)對話框
在涉及GUI程序開發(fā)的過程中,常常有模態(tài)對話框以及非模態(tài)對話框的概念
模態(tài)對話框:在子界面活動(dòng)期間,父窗口是無法進(jìn)行消息響應(yīng)。獨(dú)占用戶輸入
非模態(tài)對話框:各窗口之間不影響
主要區(qū)別:非模態(tài)對話框與APP共用消息循環(huán),不會(huì)獨(dú)占用戶。
模態(tài)對話框獨(dú)占用戶輸入,其他界面無法響應(yīng)
本文內(nèi)容
Angular JS 實(shí)現(xiàn)模式對話框?;?AngularJS v1.5.3 和 Bootstrap v3.3.6。
項(xiàng)目結(jié)構(gòu)
圖 1 項(xiàng)目結(jié)構(gòu)
運(yùn)行結(jié)果
圖 1 運(yùn)行結(jié)果:大模態(tài)
index.html
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7">
<![endif]--><!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8">
<![endif]--><!--[if IE 8]>
<html class="no-js lt-ie9">
<![endif]--><!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--><head>
<meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width"><title>AngularJS 模態(tài)對話框</title><link rel="stylesheet"
href="../src/vendor/bootstrap/dist/css/bootstrap.css">
</head>
<body ng-app="myApp" class="body">
<!-- modal template -->
<script type="text/ng-template" id="myModelContent.html">
<div class="modal-header">
<h3 class="modal-title">模態(tài)框</h3>
</div>
<div class="modal-body">
<ul>
<li ng-repeat="item in items">
<a ng-click="selected.item = item">{{item}}</a>
</li>
<div class="h2">當(dāng)前選擇:
<b>{{selected.item}}</b></div>
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">
確認(rèn)
</button>
<button class="btn btn-warning" ng-click="cancel()">退出</button>
</div>
</script>
<div class="container h1">AngularJS 模態(tài)對話框</div>
<section class="row">
<section ng-controller="modalDemo" class="col-md-6"
style="margin: 40px auto; float: none; background: #fff; padding: 30px;">
<button class="btn btn-default" ng-click="open('lg')">大模態(tài)</button>
<button class="btn btn-default" ng-click="open()">中模態(tài)</button>
<button class="btn btn-default" ng-click="open('sm')">小模態(tài)</button>
<hr>
<div class="h1" ng-show="selected">當(dāng)前選擇:{{selected}}</div>
</section>
</section>
<!-- load js -->
<script src="../src/vendor/angular/angular.js">
</script>
<script
src="http://cdn.bootcss.com/angular-ui-bootstrap/0.11.2/ui-bootstrap-tpls.js">
</script>
<script src="../src/js/mymodal.js">
</script>
</body>
</html>
mymodal.js
/** * */angular.module('myApp',
[ 'ui.bootstrap' ])
// demo controller.controller('modalDemo', function($scope, $modal, $log)
{
// list
$scope.items = [ 'angularjs', 'backbone', 'canjs', 'Ember', 'react' ];
// open click
$scope.open = function(size)
{
var modalInstance = $modal.open({
templateUrl : 'myModelContent.html',
controller : 'ModalInstanceCtrl', // specify controller for modal
size : size,
resolve : {
items : function()
{
return $scope.items;
}
}
});
// modal return result
modalInstance.result.then(function(selectedItem)
{
$scope.selected = selectedItem;
}, function()
{
$log.info('Modal dismissed at: ' + new Date())
});
}})// modal controller.controller('ModalInstanceCtrl', function($scope, $modalInstance, items)
{
$scope.items = items;
$scope.selected =
{
item : $scope.items[0]
};
// ok click
$scope.ok = function()
{
$modalInstance.close($scope.selected.item);
};
// cancel click
$scope.cancel = function()
{
$modalInstance.dismiss('cancel');
}});
以上內(nèi)容是小編給大家介紹的AngularJS 模態(tài)對話框 ,希望對大家有所幫助!
- JS 模態(tài)對話框和非模態(tài)對話框操作技巧匯總
- 利用javascript打開模態(tài)對話框(示例代碼)
- javascript showModalDialog模態(tài)對話框使用說明
- JavaScript 實(shí)現(xiàn)模態(tài)對話框 源代碼大全
- JS對話框_JS模態(tài)對話框showModalDialog用法總結(jié)
- 兩種WEB下的模態(tài)對話框 (asp.net或js的分別實(shí)現(xiàn))
- js模態(tài)對話框使用方法詳解
- js實(shí)現(xiàn)div模擬模態(tài)對話框展現(xiàn)URL內(nèi)容
- ModelDialog JavaScript模態(tài)對話框類代碼
- JavaScript實(shí)現(xiàn)模態(tài)對話框?qū)嵗?/a>
- js實(shí)現(xiàn)響應(yīng)按鈕點(diǎn)擊彈出可拖拽的非模態(tài)對話框完整實(shí)例【測試可用】
相關(guān)文章
ios設(shè)備中angularjs無法改變頁面title的解決方法
今天小編就為大家分享一篇ios設(shè)備中angularjs無法改變頁面title的解決方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
在Angular項(xiàng)目使用socket.io實(shí)現(xiàn)通信的方法
這篇文章主要介紹了在Angular項(xiàng)目使用socket.io實(shí)現(xiàn)通信的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
angular動(dòng)態(tài)刪除ng-repaeat添加的dom節(jié)點(diǎn)的方法
本篇文章主要介紹了angular動(dòng)態(tài)刪除ng-repaeat添加的dom節(jié)點(diǎn)的方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-07-07
詳解Webstorm 下的Angular2.0開發(fā)之路(圖文)
這篇文章主要介紹了詳解Webstorm 下的Angular2.0開發(fā)之路(圖文) ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12
Angular2 父子組件數(shù)據(jù)通信實(shí)例
這篇文章主要介紹了Angular2 父子組件數(shù)據(jù)通信實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
Angularjs在初始化未完畢時(shí)出現(xiàn)閃爍問題的解決方法分析
這篇文章主要介紹了Angularjs在初始化未完畢時(shí)出現(xiàn)閃爍問題的解決方法,結(jié)合實(shí)例形式分析了3種常用的閃爍問題解決方法,需要的朋友可以參考下2016-08-08
Angular4實(shí)現(xiàn)鼠標(biāo)懸停3d傾斜效果
這篇文章主要介紹了Angular4實(shí)現(xiàn)鼠標(biāo)懸停3d傾斜效果,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-10-10




