gpt4 book ai didi

angularjs - 从子模态 Controller 调用父 Controller 方法(ui bootstrap)

转载 作者:行者123 更新时间:2023-12-03 06:55:47 25 4
gpt4 key购买 nike

所以这是我遇到的问题,就像我有父 Controller 和子 Controller ,它是模态 Controller ,我在父 Controller 中有一个方法,我想从子模态 Controller 调用它,我不知道什么我失踪了,但这就是我尝试过的。

  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'];

}]);


}]);

但是它给了我一个错误,没有这样的函数,我在检查方法上遇到错误,我想从模态实例 Controller 调用这个检查方法,但无法做到,请帮忙。

最佳答案

https://angular-ui.github.io/bootstrap/#/modal

Bootstrap 中的模态有一个“范围”选项,

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

using scope: $scope 应该允许您使用父 Controller 中定义的方法

示例:

    $scope.open = function (mail) {
var modalInstance = $modal.open({
templateUrl: '/orderCancellationBox.html',
controller: ModalInstanceCtrl,
scope: $scope,
resolve: {
mail: function () {
return mail;
}
}
});
};

关于angularjs - 从子模态 Controller 调用父 Controller 方法(ui bootstrap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32945586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com