$modal是一个可以迅速创建模态窗口的服务,创建部分页,控制器,并关联他们

$modal仅有一个方法open(options)

  • templateUrl:模态窗口的地址
  • template:用于显示html标签
  • scope:一个作用域为模态的内容使用(事实上,$modal会创建一个当前作用域的子作用域)默认为$rootScope
  • controller:为$modal指定的控制器,初始化$scope,该控制器可用$modalInstance注入
  • resolve:定义一个成员并将他传递给$modal指定的控制器,相当于routes的一个reslove属性,如果需要传递一个objec对象,需要使用angular.copy()
  • backdrop:控制背景,允许的值:true(默认),false(无背景),“static” - 背景是存在的,但点击模态窗口之外时,模态窗口不关闭
  • keyboard:当按下Esc时,模态对话框是否关闭,默认为ture
  • windowClass:指定一个class并被添加到模态窗口中

open方法返回一个模态实例,该实例有如下属性

  • close(result):关闭模态窗口并传递一个结果
  • dismiss(reason):撤销模态方法并传递一个原因
  • result:一个契约,当模态窗口被关闭或撤销时传递
  • opened:一个契约,当模态窗口打开并且加载完内容时传递的变量

另外,$modalInstance扩展了两个方法$close(result)$dismiss(reason),这些方法很容易关闭窗口并且不需要额外的控制器

  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(){//模态窗口打开之后执行的函数
  46. console.log('modal is opened');
  47. });
  48. modalInstance.result.then(function (result) {
  49. console.log(result);
  50. }, function (reason) {
  51. console.log(reason);//点击空白区域,总会输出backdrop click,点击取消,则会暑促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. };

modal的使用的更多相关文章

  1. Bootstrap 模态框(Modal)插件

    页面效果: html+js: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. 学会用bootstrap的modal和carousel

    bootstrap框架提供了很多好用的javascript组件,可以很方便的实现常用的js效果,比如点击弹出一个div(modal).下拉菜单.旋转木马(carousel或slider),非常适合前端 ...

  3. angularjs 弹出框 $modal

    angularjs 弹出框 $modal 标签: angularjs 2015-11-04 09:50 8664人阅读 评论(1) 收藏 举报  分类: Angularjs(3)  $modal只有一 ...

  4. yii2 modal弹窗之ActiveForm ajax表单异步验证

    作者:白狼 出处:http://www.manks.top/yii2_modal_activeform_ajax.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位 ...

  5. yii2中如何使用modal弹窗之基本使用

    作者:白狼 出处:http://www.manks.top/yii2_modal_baseuse.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, ...

  6. Yii2 modal中 ajax提交表单

    view: // view 代码 $form = ActiveForm::begin(['id' => $model->formName()]); // js 代码 $js = <& ...

  7. js控制Bootstrap 模态框(Modal)插件

    js控制Bootstrap 模态框(Modal)插件 http://www.cnblogs.com/zzjeny/p/5564400.html

  8. 解决select2在bootstrap的modal中默认不显示的问题

    在Bootstrap中的Modal,select2插件会有不显示,因为其z-index小于modal,还有另外一个问题是,修正z-index之后,select2不会自动失去焦点的问题.代码解决如下: ...

  9. 关于Delphi错误:Cannot make a visible window modal

    Delphi的fsMDIChild类型的窗体是不能使用ShowModal的,否则会弹出"Cannot make a visible window modal"异常, 但是把fsMD ...

  10. semantic modal 首次弹出位置不正确()

    暂不知是什么原因,先记录下,可以用下面这句css解决 .ui.modal{ %; }

随机推荐

  1. ffmpeg 音频转换: use ffmpeg convert the audio from stereo to mono without changing the video part

    To convert the audio from stereo to mono without changing the video part, you can use FFmpeg: ffmpeg ...

  2. PostGIS ShapeFile 导入数据

    系统环境:WIN10 相关软件:PostgresSQL+PostGIS+QGIS 1.添加postGIS数据扩展 (1).打开PostgresSQL 客户端pgAdmin,在需要导入shp数据的数据库 ...

  3. angular报$injector / unpr的错误

    原因:angular引用未定义的错误,因为JS代码压缩过后找不到申明的变量,,没在使用之前定义,且代码被压缩,则报错(变量压缩后会变成单个字母无法识别,需在引用前分别定义): 解决:angular.m ...

  4. Apache htpasswd命令用法详解

    一. 基础 htpasswd建立和更新存储用户名.密码的文本文件, 用于对HTTP用户的basic认证. # /usr/local/apache/bin/htpasswd –help Usage: h ...

  5. 【如何快速的开发一个完整的iOS直播app】(美颜篇)

    原文转自:袁峥Seemygo    感谢分享.自我学习 前言 在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播app(原理篇) 开发一款直播app,美颜功能是很重 ...

  6. IOS常见错误之一连线错误

    在IOS编程中,UI方面,对于新手,接触时,不免喜欢拖控件,觉得省去了一些麻烦,其实在操作控件的过程中也有很多问题需要注意 本人今天就说下遇到的一个问题. setValue:forUndefinedK ...

  7. iOStextFiled判断输入长度

    个人在开发当中发现在用textField的代理方法 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(N ...

  8. python中几个常见的黑盒子之“字典dict” 与 “集合set”

    这里说到"字典dict" 和 "集合set"类型,首先,先了解一下,对于python来说,标准散列机制是有hash函数提供的,对于调用一个__hash__方法: ...

  9. PHP测试用例文档

    PHP接口测试用例和文档 PHP在过程中的测试 采用写一个简单html表单做一个简单的post测试 PHP接口测试文档 Alpha部分主要的接口文档可查看 接口文档 功能模块 接口 登录注册模块 验证 ...

  10. MySQL 创建表

     MySQL中create table语句的基本语法是: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,. ...