Angular UI Bootstrap:如何在没有控制器的情况下关闭模式?
Angular UI Boostrap: how to close the modal without a controller?
我是 AngularJS 的新手,刚刚经历了 Angular UI 模态描述: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
});
};
来自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>
我是 AngularJS 的新手,刚刚经历了 Angular UI 模态描述: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
});
};
来自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>