如何从 angular js 另一个控制器中调用 ui bootstrap 模态弹出控制器

How to call ui bootstrap modal popup controller from within angular js another controller

我如何从另一个控制器内部调用 angular ui bootstrap 模态弹出窗口,因为条件就像我需要从函数内部调用它而不是从视图调用它

       App.controller('MailFolderController', ['$scope', '$http', '$timeout', '$stateParams', '$window', 'mails', '$interval', function ($scope, $http, $timeout, $stateParams, $window, mails, $interval) {


     $scope.check = function(){
console.log("call parent ==========>")
     // call open method in modal popup here  
   }


    App.controller('orderCancellationController', ['$scope', '$modal', function ($scope, $modal) {

$scope.open = function (mail) {
    var modalInstance = $modal.open({
        templateUrl: '/orderCancellationBox.html',
        controller: ModalInstanceCtrl,
        resolve: {
            mail: function () {
                return mail;
            }
        }
    });
};

// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.

var ModalInstanceCtrl = function ($scope, $modalInstance, mail) {

    $scope.mail = mail;
    $scope.submit = function () {
        $scope.$parent.check();
        $modalInstance.close('closed');
    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
};
ModalInstanceCtrl.$inject = ["$scope", "$modalInstance", 'mail'];

 }]);


}]);

所以我想从检查方法内部调用 orderCancellationController 中的打开方法,求助!!

按照我评论中的例子:

为了从另一个控制器打开模式,您必须创建一个服务,我在 app.js 文件中这样做了,如下所示:

myApp.service('modalProvider',['$modal', function ($modal) {

this.openPopupModal = function () {
    var modalInstance = $modal.open({
        templateUrl: '/orderCancellationBox.html',
        controller: 'ModalInstanceCtrl'
    });
};
}]);

然后在我希望打开模式的控制器中,我注入 'modalProvider' 服务,如下所示:

 App.controller('MailFolderController', ['$scope', '$http', '$timeout', '$stateParams', '$window', 'mails', '$interval','modalProvider', function ($scope, $http, $timeout, $stateParams, $window, mails, $interval, modalProvider) {

// function to open modal
 $scope.check = function(){
    modalProvider.openPopupModal();
}