So here is the condition i m having trouble with , its like i have parent controller and a child controller which is a modal controller , i have a method in parent controller which i want to call from child modal controller, i dont know what i m missing but thats what i have tried.
所以这里是我遇到麻烦的条件,它就像我有父控制器和一个儿童控制器,它是一个模态控制器,我有一个方法在父控制器,我想从儿童模态控制器调用,我不知道我失踪但是这就是我所尝试的。
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'];
}]);
}]);
but it gives me an error no such function , i m getting error on check method, i want to call this check method from modal instance controller , but unable to do , please help.
但它给了我一个错误没有这样的功能,我在检查方法上得到错误,我想从模态实例控制器调用此检查方法,但无法做,请帮助。
2 个解决方案
#1
12
https://angular-ui.github.io/bootstrap/#/modal
Modal in bootstrap has an 'scope' option,
bootstrap中的模态有一个'scope'选项,
scope - a scope instance to be used for the modal's content (actually the $modal service is going to create a child scope of a provided scope). Defaults to $rootScope
scope - 要用于模态内容的范围实例(实际上$ modal服务将创建提供范围的子范围)。默认为$ rootScope
using scope: $scope
should allow you to use methods defined in your parent controller
使用范围:$ scope应该允许您使用父控制器中定义的方法
example:
$scope.open = function (mail) {
var modalInstance = $modal.open({
templateUrl: '/orderCancellationBox.html',
controller: ModalInstanceCtrl,
scope: $scope,
resolve: {
mail: function () {
return mail;
}
}
});
};
#2
1
Resolve $scope in $modal and simply call $scope.parent.check , and you are done !!
在$ modal中解析$ scope并简单地调用$ scope.parent.check,你就完成了!
#1
12
https://angular-ui.github.io/bootstrap/#/modal
Modal in bootstrap has an 'scope' option,
bootstrap中的模态有一个'scope'选项,
scope - a scope instance to be used for the modal's content (actually the $modal service is going to create a child scope of a provided scope). Defaults to $rootScope
scope - 要用于模态内容的范围实例(实际上$ modal服务将创建提供范围的子范围)。默认为$ rootScope
using scope: $scope
should allow you to use methods defined in your parent controller
使用范围:$ scope应该允许您使用父控制器中定义的方法
example:
$scope.open = function (mail) {
var modalInstance = $modal.open({
templateUrl: '/orderCancellationBox.html',
controller: ModalInstanceCtrl,
scope: $scope,
resolve: {
mail: function () {
return mail;
}
}
});
};
#2
1
Resolve $scope in $modal and simply call $scope.parent.check , and you are done !!
在$ modal中解析$ scope并简单地调用$ scope.parent.check,你就完成了!