我目前正在使用 angular-ui-bootstrap $modal 来显示一个对话框,让用户搜索和选择一个文件。文件列表来自 box.com,因此我使用 box API 来搜索文件并生成缩略图以显示在搜索结果中的每个文件旁边。
缩略图生成非常慢,用户需要在同一页面中多次调用此搜索对话框。因此,如果搜索对话框在重新打开时包含先前的搜索结果,这将对用户有所帮助。
问题是如何重用(即显示/隐藏)相同的模态实例?Angular-ui 似乎每次都会破坏/重新创建对话框。与角带相同。
编辑
这是一个Plunkr:
var app = angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function($scope, $modal, $log) {
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
});
modalInstance.result.then(function() {
$log.info('Modal closed at: ' + new Date());
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
};
};
// 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) {
$scope.friends = [{
name: 'John',
phone: '555-1276'
}, {
name: 'Mary',
phone: '800-BIG-MARY'
}, {
name: 'Mike',
phone: '555-4321'
}, {
name: 'Adam',
phone: '555-5678'
}, {
name: 'Julie',
phone: '555-8765'
}, {
name: 'Juliette',
phone: '555-5678'
}];
$scope.ok = function() {
$modalInstance.close('close');
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};