所以这里是我遇到麻烦的条件,它就像我有父控制器和子控制器这是一个模态控制器,我有一个父控制器的方法,我想从子模态控制器调用,我不知道是什么我失踪了,但那就是我尝试过的。
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', ['$scope', '$modal', function ($scope, $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'];
}]);
}]);
但它给了我一个错误没有这样的功能,我在检查方法上得到错误,我想从模态实例控制器调用这个检查方法,但无法做,请帮忙。
答案 0 :(得分:12)
https://angular-ui.github.io/bootstrap/#/modal
bootstrap中的模态有一个'scope'选项,
范围 - 用于模态内容的范围实例(实际上,$ modal服务将创建提供范围的子范围)。默认为$ rootScope
使用scope: $scope
应该允许您使用父控制器中定义的方法
示例:
$scope.open = function (mail) {
var modalInstance = $modal.open({
templateUrl: '/orderCancellationBox.html',
controller: ModalInstanceCtrl,
scope: $scope,
resolve: {
mail: function () {
return mail;
}
}
});
};
答案 1 :(得分:1)
在$ modal中解析$ scope并简单地调用$ scope.parent.check,你就完成了!