我在我的 AngularJS 应用程序中使用 bootstrap 3 模态作为对话框确认。当我隐藏模态并重定向时,模态的背景仍然存在。
$scope.delete = function () {
DataService.delete()
.then(function () {
$("#delete").modal("hide");
$location.path("/");
});
}
我试过在隐藏时使用回调
$("#delete").on('hidden.bs.modal', function () {
$location.path("/");
}
但是这里面的延迟很多。
有更好的方法吗?
最佳答案
But the delay in this is a lot.
您可能忘记调用 $scope.$apply()
。尝试将其更改为以下内容(如果延迟是唯一的问题)并且延迟应该是正常的:
$("#delete").on('hidden.bs.modal', function () {
$location.path("/");
$scope.$apply();
});
与 Angular 交互的所有在 Angular 外部调用的代码(在本例中是从 jQuery 事件调用的)都应该调用 $apply()
。
关于javascript - 隐藏 Bootstrap 3 Modal 和 AngularJS 重定向($location.path),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19356535/