我的应用程序中有两种状态。在每种状态下,我打开一个模态对话框,该对话框具有自己的控制器:parentCtrl
和childCtrl
。我想返回到select(config)
函数中的父模态,并将config
值返回到父状态,只需进入parentCtrl
.
$stateProvider.state('parent', {
url: "...",
onEnter: function ($stateParams, $state, $uibModal) {
$uibModal.open({
templateUrl: '...',
controller: function ($scope, $uibModalInstance) {
...
},
controllerAs: 'parentCtrl'
});
}
});
$stateProvider.state('parent.child', {
url: "...",
onEnter: function ($stateParams, $state, $uibModal) {
$uibModal.open({
templateUrl: '...',
controller: function ($scope, $uibModalInstance) {
this.select = function (config) {
debugger;
alert("Hall:"+ config.hallName+", configuration:"+ config.name+", configId: "+ config.id);
$uibModalInstance.close({data: config});
};
},
controllerAs: 'childCtrl'
}).result.finally(function () {
debugger;
$state.go('^');
});
}
});
对于引导模态,模态作用域将是控制器作用域的子级,并且在角度作用域中是链接的。
因此,如果您使用 : $scope.模态 = {}; $scope.modal.newData = function(data){};
你应该能够在模态控制器中做到: $scope.modal.newData (data);
注意:中间对象模态是因为范围继承的限制,你可能对这个javascript没有问题,但你可能有模板,所以我在玩范围继承时总是使用间对象。
编辑:没有看到它是 2 个独立模态。最好的方法是使用我发布的内容,并从父范围数据中关闭并再次打开父模式以刷新它。
否则,您可以使用 $scope/$rootScope.$on/$emit 在 angularjs 中发出/侦听事件。
对于这类内容,请使用 $rootScope.$on 侦听,使用 $rootScope.emit 发送事件。
子模态的结果可以传递参数。
.result.then(function (data) {
$state.go('^', data);
});
此数据是您在 .close() 操作中输入的参数。您可以通过在父状态定义中添加以下内容来捕获状态配置中的这些参数
params: {
data: {}
}