日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【转】AngularJs 弹出框 model(模态框)

發(fā)布時(shí)間:2025/3/13 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】AngularJs 弹出框 model(模态框) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原文轉(zhuǎn)至?http://blog.csdn.net/violet_day/article/details/17170585?

$modal是一個(gè)可以迅速創(chuàng)建模態(tài)窗口的服務(wù),創(chuàng)建部分頁(yè),控制器,并關(guān)聯(lián)他們

$modal僅有一個(gè)方法open(options)

  • templateUrl:模態(tài)窗口的地址
  • template:用于顯示html標(biāo)簽
  • scope:一個(gè)作用域?yàn)槟B(tài)的內(nèi)容使用(事實(shí)上,$modal會(huì)創(chuàng)建一個(gè)當(dāng)前作用域的子作用域)默認(rèn)為$rootScope
  • controller:為$modal指定的控制器,初始化$scope,該控制器可用$modalInstance注入
  • resolve:定義一個(gè)成員并將他傳遞給$modal指定的控制器,相當(dāng)于routes的一個(gè)reslove屬性,如果需要傳遞一個(gè)objec對(duì)象,需要使用angular.copy()
  • backdrop:控制背景,允許的值:true(默認(rèn)),false(無(wú)背景),“static”?-?背景是存在的,但點(diǎn)擊模態(tài)窗口之外時(shí),模態(tài)窗口不關(guān)閉
  • keyboard:當(dāng)按下Esc時(shí),模態(tài)對(duì)話框是否關(guān)閉,默認(rèn)為ture
  • windowClass:指定一個(gè)class并被添加到模態(tài)窗口中

open方法返回一個(gè)模態(tài)實(shí)例,該實(shí)例有如下屬性

  • close(result):關(guān)閉模態(tài)窗口并傳遞一個(gè)結(jié)果
  • dismiss(reason):撤銷模態(tài)方法并傳遞一個(gè)原因
  • result:一個(gè)契約,當(dāng)模態(tài)窗口被關(guān)閉或撤銷時(shí)傳遞
  • opened:一個(gè)契約,當(dāng)模態(tài)窗口打開并且加載完內(nèi)容時(shí)傳遞的變量

另外,$modalInstance擴(kuò)展了兩個(gè)方法$close(result)、$dismiss(reason),這些方法很容易關(guān)閉窗口并且不需要額外的控制器

HTML?

1 <!DOCTYPE html> 2 <html ng-app="ModalDemo"> 3 <head> 4 <title></title> 5 <link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> 6 <script src="lib/angular/angular.min.js"></script> 7 <script src="lib/bootstrap-gh-pages/ui-bootstrap-tpls-0.7.0.min.js"></script> 8 <script src="lib/angular/i18n/angular-locale_zh-cn.js"></script> 9 </head> 10 <body> 11 <div ng-controller="ModalDemoCtrl"> 12 <script type="text/ng-template" id="myModalContent.html"> 13 <div class="modal-header"> 14 <h3>I'm a modal!</h3> 15 </div> 16 <div class="modal-body"> 17 <ul> 18 <li ng-repeat="item in items"> 19 <a ng-click="selected.item = item">{{ item }}</a> 20 </li> 21 </ul> 22 Selected: <b>{{ selected.item }}</b> 23 </div> 24 <div class="modal-footer"> 25 <button class="btn btn-primary" ng-click="ok()">OK</button> 26 <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 27 </div> 28 </script> 29 <button class="btn" ng-click="open()">Open me!</button> 30 </div> 31 <script> 32 var ModalDemo = angular.module('ModalDemo', ['ui.bootstrap']); 33 var ModalDemoCtrl = function ($scope, $modal, $log) { 34 $scope.items = ['item1', 'item2', 'item3']; 35 $scope.open = function () { 36 var modalInstance = $modal.open({ 37 templateUrl: 'myModalContent.html', 38 controller: ModalInstanceCtrl, 39 resolve: { 40 items: function () { 41 return $scope.items; 42 } 43 } 44 }); 45 modalInstance.opened.then(function(){//模態(tài)窗口打開之后執(zhí)行的函數(shù) 46 console.log('modal is opened'); 47 }); 48 modalInstance.result.then(function (result) { 49 console.log(result); 50 }, function (reason) { 51 console.log(reason);//點(diǎn)擊空白區(qū)域,總會(huì)輸出backdrop click,點(diǎn)擊取消,則會(huì)暑促cancel 52 $log.info('Modal dismissed at: ' + new Date()); 53 }); 54 }; 55 }; 56 var ModalInstanceCtrl = function ($scope, $modalInstance, items) { 57 $scope.items = items; 58 $scope.selected = { 59 item: $scope.items[0] 60 }; 61 $scope.ok = function () { 62 $modalInstance.close($scope.selected); 63 }; 64 $scope.cancel = function () { 65 $modalInstance.dismiss('cancel'); 66 }; 67 }; 68 </script> 69 </body> 70 </html>

?

轉(zhuǎn)載于:https://www.cnblogs.com/wohenxion/p/4478477.html

總結(jié)

以上是生活随笔為你收集整理的【转】AngularJs 弹出框 model(模态框)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。