gpt4 book ai didi

angularjs - Angular 模态让用户点击它

转载 作者:行者123 更新时间:2023-12-02 07:30:11 24 4
gpt4 key购买 nike

我的 angularJS 应用程序中有一个模态对话框,但是当用户单击模态后面的灰色站点时,模态将关闭。我希望模态表现得像一个模态,即,你必须响应里面的内容才能关闭它。谁能告诉我如何实现这一目标?这是一个 jsbin:

http://jsbin.com/aDuJIku/2/edit

编辑:供将来引用的代码:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app='ModalDemo'>
<div ng-controller='MyCtrl'>
<button ng-click='toggleModal()'>Open Modal Dialog</button>
<modal-dialog show='modalShown' width='400px' height='60%'>
<p>Modal Content Goes here<p>
</modal-dialog>
</div>
</body>
</html>

app = angular.module('ModalDemo', []);
app.directive('modalDialog', function() {
return {
restrict: 'E',
scope: {
show: '='
},
replace: true, // Replace with the template below
transclude: true, // we want to insert custom content inside the directive
link: function(scope, element, attrs) {
scope.dialogStyle = {};
if (attrs.width)
scope.dialogStyle.width = attrs.width;
if (attrs.height)
scope.dialogStyle.height = attrs.height;
scope.hideModal = function() {
scope.show = false;
};
},
template: "<div class='ng-modal' ng-show='show'><div class='ng-modal-overlay' ng-click='hideModal()'></div><div class='ng-modal-dialog' ng-style='dialogStyle'><div class='ng-modal-close' ng-click='hideModal()'>X</div><div class='ng-modal-dialog-content' ng-transclude></div></div></div>"
};
});

app.controller('MyCtrl', ['$scope', function($scope) {
$scope.modalShown = false;
$scope.toggleModal = function() {
$scope.modalShown = !$scope.modalShown;
};
}]);

最佳答案

假设您使用的是 Bootstrap,将背景设置为静态。

var modalInstance = $modal.open({
templateUrl: '/App/Documents/Templates/DeleteDocumentDialogTemplate.html',
backdrop: 'static'
});

关于angularjs - Angular 模态让用户点击它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22760850/

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