angularjs – 从子模态控制器(ui bootstrap)调用父控制器方法

前端之家收集整理的这篇文章主要介绍了angularjs – 从子模态控制器(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 ==========>")
}


  App.controller('orderCancellationController','$modal',$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'];

}]);


}]);

但它给了我一个错误没有这样的功能,我在检查方法上得到错误,我想从模态实例控制器调用此检查方法,但无法做,请帮助.

https://angular-ui.github.io/bootstrap/#/modal

bootstrap中的模态有一个’scope’选项,

scope – a scope instance to be used for the modal’s content (actually the $modal service is going to create a child scope of a provided scope). Defaults to $rootScope

使用范围:$scope应该允许您使用父控制器中定义的方法

例:

$scope.open = function (mail) {
    var modalInstance = $modal.open({
        templateUrl: '/orderCancellationBox.html',scope: $scope,resolve: {
            mail: function () {
                return mail;
            }
        }
    });
};
原文链接:https://www.f2er.com/angularjs/140895.html

猜你在找的Angularjs相关文章