0

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");
    };

}]);

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

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

4

1 回答 1

0

啊,才发现问题。

我改变了这个:

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

有了这个:

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

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

于 2019-02-15T18:31:02.110 回答