【问题标题】:Open a nested modal and close current (parent) modal打开嵌套模态并关闭当前(父)模态
【发布时间】:2019-07-09 22:12:47
【问题描述】:

来自controller1 我正在打开这样的模式:

angular.module('myApp').controller('controller1', ['$scope', '$uibModal', function($scope, $uibModal) {

    $scope.openFirstModal = function() {

        var modalScope = $scope.$new();

        var modalInstance = $uibModal.open({
            templateUrl: 'views/modal1.html',
            controller: 'modal1Controller',
            scope: modalScope,
            resolve: {},
            size: 'lg'
        });

        modalScope.uibModalInstance = modalInstance;
    };

}]);

然后,我打开一个这样的嵌套模式:

angular.module('myApp').controller('modal1', ['$scope', '$uibModal', function($scope, $uibModal) {

    $scope.openSecondModal = function() {

        // Open nested modal
        var modalScope = $scope.$new();

        var modalInstance = $uibModal.open({
            templateUrl: 'views/modal2.html',
            controller: 'modal2Controller',
            scope: modalScope,
            resolve: {},
            size: 'lg'
        });

        modalScope.uibModalInstance = modalInstance;

        // Close this modal
        $scope.uibModalInstance.dismiss('cancel');
    };

}]);

但最后一部分:

        // Close this modal
        $scope.uibModalInstance.dismiss('cancel');

...在嵌套模式中引发问题。在我的嵌套模式中没有任何作用:

angular.module('myApp').controller('modal2', ['$scope', '$uibModal', function($scope, $uibModal) {

    $scope.test = function() {
        console.log("test");
    };

}]);

如果我删除有问题的代码,嵌套模式可以正常工作。

如何关闭第一个模态而不使嵌套模态失败?

【问题讨论】:

    标签: angularjs bootstrap-ui


    【解决方案1】:

    啊,刚刚发现问题了。

    我改变了这个:

        // Open nested modal
        var modalScope = $scope.$new();
    

    有了这个:

        // Open nested modal
        var modalScope = $rootScope.$new();
    

    这样嵌套模式不依赖于他的父级。 父母可以死,孩子会继续活着

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2016-05-20
      • 2021-05-22
      相关资源
      最近更新 更多