我想在外面点击或按键盘中的esc
时阻止模态关闭。所以我使用了backdrop:'static'
和keyboard:false
,如下所示,
var app = angular.module('MyApp', ['ngDialog', 'chatSocket']);
app.controller('MainCtrl', function ($scope, ngDialog) {
$scope.openChatBox = function() {
ngDialog.openConfirm({
template: 'chatBox.html',
controller: 'msgController',
backdrop: 'static',
keyboard: false,
scope: $scope //Pass the scope object if you need to access in the template
}).then(
function(value) {
//You need to implement the saveForm() method which should return a promise object
$scope.closeChat().then(
);
},
function(value) {
//Cancel or do nothing
}
);
};
});
点击按钮打开模态,
<button ng-click="openChatBox()" >Open</button>
我的代码有什么问题,为什么不工作?
答案 0 :(得分:2)
对于$modal
,我们使用backdrop
和keyboard
选项来实现它,但对于ngDialog
,选项为closeByDocument
和closeByEscape
。
$scope.openChatBox = function() {
ngDialog.openConfirm({
template: 'chatBox.html',
controller: 'msgController',
closeByDocument: false,
closeByEscape: false,
scope: $scope //Pass the scope object if you need to access in the template
}).then(
function(value) {
//You need to implement the saveForm() method which should return a promise object
$scope.closeChat().then(
);
},
function(value) {
//Cancel or do nothing
}
);
};
答案 1 :(得分:1)
使用closeByDocument:false,而不是背景,以防止页面在背景点击时关闭。
template: 'chatBox.html',
controller: 'msgController',
closeByDocument: false,
keyboard: false,
答案 2 :(得分:0)
在backdrop: 'static'
:
$uibModal.open()
$uibModal.open({
template: 'chatBox.html',
controller: 'msgController',
backdrop: 'static', // <--
...
});
答案 3 :(得分:0)
似乎ngDialog不支持背景静态。所以最好使用$ model.open
$scope.openChatBox = function() {
var modalInstance = $modal.open({
template: 'chatBox.html',
controller: 'msgController',
backdrop: 'static',
keyboard: false,
scope: $scope
});
modalInstance.result.then(function () {
function(value) {
// do something
},
function(value) {
//Cancel or do nothing
}
});
}