【问题标题】:Closing all the modal bootstrap pop up in Angular JS关闭Angularjs中的所有模式引导弹出窗口
【发布时间】:2016-12-30 13:45:04
【问题描述】:

当用户点击最终确认模态弹窗的关闭按钮时,我想关闭所有模态弹窗。

但是打开的模态窗口确实属于不同的控制器。这是sn-p:

function getQuickCasePopup($scope, $uibModal, $rootScope) {
    var templateUrl = BasePath + 'App/Transaction/Views/common/QuickCaseSearch.tpl.html';
    var controller = 'QuickCaseSearchCtrl';
    OpenModal($scope, $uibModal, null, templateUrl, controller, null, null, '', $rootScope);
}

function getAddCasePopup($scope, $uibModal, $rootScope) {
    var templateUrl = BasePath + 'App/Transaction/Views/common/CreateCase.tpl.html';
    var controller = 'AddCaseCtrl';
    OpenModal($scope, $uibModal, null, templateUrl, controller, null, null, '', $rootScope);
}

function getAdvanceCasePopup($scope, $uibModal, $rootScope) {
    var templateUrl = BasePath + 'App/Transaction/Views/common/AdvanceCaseSearch.tpl.html';
    var controller = 'AdvanceCaseCtrl';
    OpenModal($scope, $uibModal, null, templateUrl, controller,null, null, 'lg', $rootScope);
}

function OpenModal($scope, $uibModal, $stateParams, templ, ctrl, grid, row, size, $rootScope) {

    var CssClass = '';
    if (size === 'lg') {
        CssClass = 'app-modal-window';
    }

    var ModalInstance = ModalInstance || $uibModal.open({
        animation: $scope.animationsEnabled,
        templateUrl: templ,
        controller: ctrl,  // Logic in instantiated controller 
        windowClass: CssClass
    }); 

确认弹窗代码如下:

$("#iConfirmationModal").modal();

$("#iConfirmationModal").on('hidden.bs.modal', function () {

    //$(".app-modal-window").dialog("close"); //Did not work

    $state.go('transaction.search', {});
});

所以我想关闭所有的模态弹窗然后重定向。我能达到同样的效果吗?

【问题讨论】:

  • 这些模态是否在彼此之上打开,第二个模态是否从第一个模态中打开?
  • 没有这些模态是分开的。
  • 你应该创建一个工厂来在一个地方管理它们。

标签: javascript jquery angularjs twitter-bootstrap


【解决方案1】:

模态是一个单例对象,因此您可以调用 $scope.$close() 并关闭所有模态实例

【讨论】:

    【解决方案2】:

    您可能有多种选择,

    1. 创建一个管理所有模式状态的服务。
    2. 使用 $emit\$broadcast 进行通知。
    3. 使用像amplifyjs 这样的第三方库并在那里使用 pub\sub 操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      相关资源
      最近更新 更多