【发布时间】:2019-03-04 09:30:56
【问题描述】:
我有一个使用自己的新控制器打开的模态,我想从模态控制器调用一个函数,但该函数是在父控制器中定义的。
我将这个函数定义为从 $rootScope 调用,这是从模态中的父级调用函数的最佳方式还是将来有意义?
示例:
FormModule.controller("formCtrl", function ($scope, $http, $uibModal, $log, $rootScope) {
$rootScope.ShowReport = function ShowReport() {
//function Edit
$scope.edit = function () {
var ObjResolve = function () {
return obj;
}
var modalInstance= $uibModal.open({
animation: true,
templateUrl: 'Modal.html',
controller: 'ModalInstanceCtrl',
resolve: {
ObjResolve
}
}).result.catch(function (res) {
if (!(res === 'cancel' || res === 'escape key press')) {
//throw res;
}
});
};
});
FormModule.controller("ModalInstanceCtrl", function ($scope, $uibModal, $uibModalInstance, $http, ObjResolve, $rootScope ) {
//save Event
$scope.save = function () {
$rootScope.ShowReport();
}
});
【问题讨论】:
标签: javascript angularjs angular-ui-bootstrap