javascript - Angular UI Boostrap:如何在没有控制器的情况下关闭模式?
问题描述
我是 AngularJS 的新手,刚刚经历了 Angular UI Modal 中描述的:http ://angular-ui.github.io/bootstrap/ 。
我想创建一个简单的模式,只有一个按钮来关闭模式。如何在不为模态创建单独的控制器的情况下做到这一点?模态模板中是否有ng-click
事件脚本来完成这项工作?比如this.close()
...
我想要达到的效果是这样的:
模板:
<div class="modal-header">
<h3>Modal header</h3>
</div>
<div class="modal-body">
<h4>Just something random here</h4>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="this.close()">OK</button>
</div>
页面控制器:
$scope.openModal = function() {
$uibModal.open({
templateUrl: "modalContent.html",
// it's so simple so that I don't want a separate controller
//controller: "ModalContentCtrl",
size: '',
backdrop: 'static',
keyboard: false
});
};
解决方案
从文档:
与模态内容相关的范围增加了:
$close(result) (Type: function) - 一种可用于关闭模式并传递结果的方法。
$dismiss(reason) (Type: function) - 一种可以用来关闭模式的方法,传递一个原因。
这些方法可以轻松关闭模式窗口,而无需创建专用控制器。
所以这有效:
<div class="modal-header">
<h3>Modal header</h3>
</div>
<div class="modal-body">
<h4>Just something random here</h4>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$close()">OK</button>
</div>
推荐阅读
- php - 删除 id 在逗号分隔字符串中的行
- mysql - 如何在 Ubuntu 19.04 (Disco Dingo) 中编辑 php.ini 文件
- arm - 如何将为目标设备 STM32F072B 编写的 STM32 片段(代码示例)转换为 STM32F030r8
- c# - Xceed DateTimePicker, isEnabled 时间选择器
- python - cx_Oracle.NotSupportedError:不支持元组类型的 Python 值
- python-3.x - 如果没有下一步按钮,只有编号可用,我如何转到下一页?
- python - 编写简单的 python 密码重置代码示例时遇到问题
- python - 为什么我们需要将 (R,1) 重塑为 (R,) 以进行绘图?
- angular - 在服务器上发送表单数据时面临问题
- java - 如何使用勺子在 Maven 项目中漂亮地打印生成的源代码?