gpt4 book ai didi

javascript - Angular UI Bootstrap : how to close the modal without a controller?

转载 作者:行者123 更新时间:2023-12-01 00:55:47 27 4
gpt4 key购买 nike

我是 AngularJS 的新手,刚刚经历了 Angular UI Modal,描述如下:http://angular-ui.github.io/bootstrap/ .

我想创建一个简单的模式,只有一个按钮来关闭模式。如何在不为模式创建单独的 Controller 的情况下执行此操作?模态模板中是否有 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>

页面 Controller :

  $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
});
};

最佳答案

来自docs :

The scope associated with modal's content is augmented with:

$close(result) (Type: function) - A method that can be used to close a modal, passing a result.

$dismiss(reason) (Type: function) - A method that can be used to dismiss a modal, passing a reason.

Those methods make it easy to close a modal window without a need to create a dedicated controller.

所以这有效:

<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>

关于javascript - Angular UI Bootstrap : how to close the modal without a controller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56593807/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com