[英]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');
};
})
I invoke this modal from a controller say 'controllerA'. 我从控制器“ 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'. 我需要在模板的自定义指令控制器的控制器中获得模态控制器功能,例如$ modalInstance.dismiss和$ modalInstance.close,例如“ controllerB”。
My template is like this: 我的模板是这样的:
<custom-form></custom-form>
There are two way to call method of another controller 调用另一个控制器的方法有两种方法
1 Sharing controller 1个共享控制器
we can share controller's method using $controller
in app.controller 我们可以在app.controller中使用$controller
共享控制器的方法
2.Sharing rootScope 2,共享rootScope
share $rootScope both controller using $rootScope
使用$rootScope
共享$ rootScope两个控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.