我目前使用angular-ui-bootstrap $ modal來顯示一個讓用戶搜索並選擇一個文件的對話框。文件列表來自box.com,因此我使用Box API來搜索文件並生成縮略圖以顯示在搜索結果中的每個文件旁邊。如何用AngularJS隱藏/顯示相同的模態實例?
生成縮略圖非常慢,用戶需要在同一頁面多次調用此搜索對話框。因此,如果搜索對話框在重新打開時包含先前的搜索結果,則對用戶有幫助。
問題是我該如何重新使用(即顯示/隱藏)相同的模態實例? 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');
};
};
試試我的對話模塊https://github.com/doodeec/dcom-angular-dialog它支持的選項隱藏它時保留DOM中的對話框 – doodeec