angularjs - 从另一个控制器访问 ui-bootstrap 模式关闭和关闭功能 [英] angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller
问题描述
我有如图所示的模式调用服务.
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
共享 $rootScope 两个控制器
share $rootScope both controller using $rootScope
这篇关于angularjs - 从另一个控制器访问 ui-bootstrap 模式关闭和关闭功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!