angularjs-从另一个控制器访问ui-bootstrap模式关闭和关闭功能 [英] angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller

查看:82
本文介绍了angularjs-从另一个控制器访问ui-bootstrap模式关闭和关闭功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供了如图所示的模式调用服务.

i have service for modal invoking as shown.

.service('modalService', ['$modal', function ($modal) {

        var modalDefaults = {
            backdrop: 'static',
            keyboard: true,
            modalFade: true
        };

        this.showModal = function (template) {

            modalDefaults.template = template;

            modalDefaults.controller = 'modalController';
            return $modal.open(modalDefaults).result;
        };

    }])

.controller('modalController', function ($scope, $modalInstance) {
        console.log('modalController');
        $scope.ok = function () {
            $modalInstance.close('okResult');
        };
        $scope.cancel = function (result) {
            $modalInstance.dismiss('cancel');
        };
    })

我从控制器"controllerA"调用此模式. 用于模式的模板包含自定义指令. 我需要在模板的自定义指令控制器的控制器中获得模态控制器功能,例如$ modalInstance.dismiss和$ modalInstance.close,例如"controllerB".

I invoke this modal from a controller say 'controllerA'. The template used for modal contains custom drectives. I need to get the modal controller functionalities like $modalInstance.dismiss and $modalInstance.close in the controller of the custom directive controller of the template, say 'controllerB'.

我的模板是这样的:

<custom-form></custom-form>

推荐答案

调用另一种控制器的方法有两种方法

There are two way to call method of another controller

1个共享控制器

我们可以使用app.controller中的$controller共享控制器的方法

we can share controller's method using $controller in app.controller

2.共享rootScope

使用$rootScope

这篇关于angularjs-从另一个控制器访问ui-bootstrap模式关闭和关闭功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆