如何为多个控制器使用引导模态
How to use bootstrap modal for multiple controllers?
我想用不同的父控制器使用相同的模态窗口,模态控制器的唯一区别是我正在调用的单独工厂,例如Ctrl-1-Factory.getServerFiles
,所以同样我想在Ctrl2
填充模态时调用Ctrl-2-Factory
。
ModalCtrl.js
angular.module('App').controller('ServerFilesCtrl', function($scope, $rootScope, FileSaver, $uibModalInstance, Ctrl-1-Factory, $uibModal) {
'use strict';
$scope.cancel = function() {
$uibModalInstance.close();
}
Ctrl-1-Factory.getServerFiles().then(function(response) {
$scope.data = response.data;
console.log($scope.data);
});
});
ctrl - 1. - js
$scope.modalInstance = $uibModal.open({
templateUrl: '/web/global/modal.html',
controller:'ModalController'
});
ctrl - 2. - js
$scope.modalInstance = $uibModal.open({
templateUrl: '/web/global/modal.html',
controller:'ModalController'
});
你可以把它封装在一个service方法中。
angular.module('App').factory('FilesModal', function() {
return {
openModal: openModal
};
function openModal() {
return $uibModal.open({
templateUrl: '/web/global/modal.html',
controller: 'ModalController'
});
}
});
angular.module('App').controller('Ctrl1', function(FilesModal) {
$scope.someEventFunction = someEventFunction;
function someEventFunction() {
$scope.modalInstance = FilesModal.openModal();
}
});
根据需要传入参数使其更健壮
相关文章:
- 如何在angular ui模态控制器中定义函数
- 在angularJS中使用模态窗口时,在控制器之间共享对象数组
- Angularjs - 观察模态窗口从另一个控制器关闭
- angularjs模态将数据传输到外部控制器的正确方法
- 显示控制器angular js的模态
- 使用模态ng控制器作为常规控制器
- 将数据从 Angular 模态的控制器传递回主控制器
- 将角度模态数据传递到主控制器
- 如何打开模态窗体,在控制器中执行操作,并在 Grails 中呈现结果
- AngularJS 模态对话框表单对象在控制器中未定义
- Angularjs $compiling模态窗口内容创建孤立的控制器
- 从 Angularjs 中的控制器关闭模态
- 如何在同一页面上的同一控制器上拥有两种不同的模态
- Angularjs:如何从模态控制器和指令控制器访问主控制器
- 为什么不能从ui-bootstrap模态控制器中绑定$scope字符串值?
- 在加载AngularStrap模态控制器之前解析promise
- 从模态控制器AngularJS调用主控制器函数
- Angular UI模态控制器不暴露给指令
- UI角度模态控制器$scope值处理错误
- 从模态控制器分配数据源