$modalInstance 对话框关闭,但屏幕保持灰色且无法访问
$modalInstance dialog box closes, but screen remains grayed out and inaccessible
我正在使用 angular-ui 打开和关闭模式。当我用 submit(object)
或 dismiss(message)
关闭它时,对话框关闭,但屏幕保持灰色,我无法访问我的应用程序。一些代码:
parent控制器(相关部分):
$scope.deleteConfirm = function(toDelete) {
console.log(toDelete);
var modalObj = {
templateUrl: 'views/templates/delete.html',
controller: 'DeleteCtrl',
size: 'sm',
resolve: {
toDelete: function() {
return toDelete;
},
collection: function() {
return $scope.users;
}
}
}
var modalInstance = $modal.open(modalObj);
modalInstance.result.then(function (deletedItem) {
console.log(deletedItem);
});
};
parent html:
<button class="btn btn-danger btn-xs" ng-click="deleteConfirm(user)">X</button>
模态控制器:
.controller('DeleteCtrl', ['$scope', '$modalInstance', 'toDelete', 'collection', function ($scope, $modalInstance, toDelete, collection) {
$scope.toDelete = toDelete;
$scope.remove = function() {
collection.$remove(toDelete).then(function(ref) {
$modalInstance.close(ref);
});
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
模态模板:
<div class = "ll-modal">
<div class="modal-header">
<h3 class="modal-title">Confirm Delete</h3>
</div>
<div class="modal-body">
Are you sure you want to delete this item? It will be gone forever.
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="remove()">Delete Permanently</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
模态与 ng-animate
的 1.4.x angular 版本一起使用时似乎存在问题。由于 ng-animate
仅在转换完成后才懒惰地删除 DOM 元素,因此该流程中存在一些问题。您可以通过在模式设置中关闭动画来 quick 修复它。有一个问题 logged in Github 说 ui bootstrap 还没有被官方完全支持 1.4.x.
var modalObj = {
templateUrl: 'views/templates/delete.html',
controller: 'DeleteCtrl',
size: 'sm',
animation: false, //<-- Turn off
resolve: {
toDelete: function() {
return toDelete;
},
collection: function() {
return $scope.users;
}
}
}
或者只是全局关闭它:
app.config(function($modalProvider) {
$modalProvider.options.animation = false;
});
更新
如果你按照上面提供的 github link 你可以看到它已经在 ui bootstrap 的最新版本中得到修复,即 upgrade of 0.13.3 或更高版本将解决问题。
我在使用 angular 1.4.3 angualar-ui-bootstrap 0.13 时遇到了问题。
PSL 答案有效(删除动画)...但没有动画会导致糟糕的用户体验(恕我直言)。
由于各种原因,无法将 angular 恢复到 1.3。
我尝试将 ui-bootstrap 从 0.13 降级到 0.12.1
对我有用
我知道 ui-bootstrap 0.12.1 仅支持 angular 1.3...但是 angular 1.4.3 对我来说一切似乎都适用。鉴于我没有广泛使用 ui-bootstrap,我想这没关系,但这可能并不适用于所有人
您现在可以将 Angular 1.4.x 与 Bootstrap UI 0.13.3 一起使用,问题已解决。这是依赖项:
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.3/ui-bootstrap-tpls.js"></script>
这是我对此的快速解决方案,在您的模态 html 中粘贴即可;
<script>
$(document).ready(function () {
$("button.close").click(function () {
$(".modal-backdrop.fade").hide();
});
}); </script>
我正在使用 angular-ui 打开和关闭模式。当我用 submit(object)
或 dismiss(message)
关闭它时,对话框关闭,但屏幕保持灰色,我无法访问我的应用程序。一些代码:
parent控制器(相关部分):
$scope.deleteConfirm = function(toDelete) {
console.log(toDelete);
var modalObj = {
templateUrl: 'views/templates/delete.html',
controller: 'DeleteCtrl',
size: 'sm',
resolve: {
toDelete: function() {
return toDelete;
},
collection: function() {
return $scope.users;
}
}
}
var modalInstance = $modal.open(modalObj);
modalInstance.result.then(function (deletedItem) {
console.log(deletedItem);
});
};
parent html:
<button class="btn btn-danger btn-xs" ng-click="deleteConfirm(user)">X</button>
模态控制器:
.controller('DeleteCtrl', ['$scope', '$modalInstance', 'toDelete', 'collection', function ($scope, $modalInstance, toDelete, collection) {
$scope.toDelete = toDelete;
$scope.remove = function() {
collection.$remove(toDelete).then(function(ref) {
$modalInstance.close(ref);
});
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
模态模板:
<div class = "ll-modal">
<div class="modal-header">
<h3 class="modal-title">Confirm Delete</h3>
</div>
<div class="modal-body">
Are you sure you want to delete this item? It will be gone forever.
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="remove()">Delete Permanently</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
模态与 ng-animate
的 1.4.x angular 版本一起使用时似乎存在问题。由于 ng-animate
仅在转换完成后才懒惰地删除 DOM 元素,因此该流程中存在一些问题。您可以通过在模式设置中关闭动画来 quick 修复它。有一个问题 logged in Github 说 ui bootstrap 还没有被官方完全支持 1.4.x.
var modalObj = {
templateUrl: 'views/templates/delete.html',
controller: 'DeleteCtrl',
size: 'sm',
animation: false, //<-- Turn off
resolve: {
toDelete: function() {
return toDelete;
},
collection: function() {
return $scope.users;
}
}
}
或者只是全局关闭它:
app.config(function($modalProvider) {
$modalProvider.options.animation = false;
});
更新
如果你按照上面提供的 github link 你可以看到它已经在 ui bootstrap 的最新版本中得到修复,即 upgrade of 0.13.3 或更高版本将解决问题。
我在使用 angular 1.4.3 angualar-ui-bootstrap 0.13 时遇到了问题。
PSL 答案有效(删除动画)...但没有动画会导致糟糕的用户体验(恕我直言)。
由于各种原因,无法将 angular 恢复到 1.3。
我尝试将 ui-bootstrap 从 0.13 降级到 0.12.1 对我有用
我知道 ui-bootstrap 0.12.1 仅支持 angular 1.3...但是 angular 1.4.3 对我来说一切似乎都适用。鉴于我没有广泛使用 ui-bootstrap,我想这没关系,但这可能并不适用于所有人
您现在可以将 Angular 1.4.x 与 Bootstrap UI 0.13.3 一起使用,问题已解决。这是依赖项:
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.3/ui-bootstrap-tpls.js"></script>
这是我对此的快速解决方案,在您的模态 html 中粘贴即可;
<script>
$(document).ready(function () {
$("button.close").click(function () {
$(".modal-backdrop.fade").hide();
});
}); </script>