我有以下的模板,有4個模式類似(只是在ID的區別):鏈接情態動詞的角度
<div id="modal_1">
<div class="modal-header">
<h3>I'm a modal 1!</h3>
</div>
<div class="modal-body">
<ul>
<li ng-repeat="item in items">
<a ng-click="selected.item = item">{{ item }}</a>
</li>
</ul>
Selected: <b>{{ selected.item }}</b>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</div>
我app.js的樣子:
angular.module('app', ['ui.bootstrap', 'ngCookies']);
var ModalDemoCtrl = function ($scope, $cookieStore, $modal, $log) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.open = function() {
if(!$cookieStore.get('abc')){
var modalInstance = $modal.open({
templateUrl: 'modalContent.html',
controller: ModalInstanceCtrl,
resolve: {
items: function() {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
};
}
};
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function() {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
`
我的要求:
我希望顯示4模態(一個接一個,當用戶點擊「確定」),如果一個特定的cookie不可用並且用戶還沒有「取消」任何其他之前的模式。
但我無法鏈接模態。
如何鏈接模態,以便之前的模態打開另一個模態直到條件不滿足?
一個新的模式,而不是最後一個,或頂新模式最後一個? – klskl
顯示的代碼是直接來自模態文檔演示的代碼。它沒有顯示任何嘗試打開不同的模式。圍繞模態初始化代碼創建一個工廠函數,並傳入步驟信息,以便您可以在結果回調中更改模板和邏輯 – charlietfl
您可以使用承諾'$ q'鏈接幾個模塊。如果用戶單擊「確定」,則執行「解析」,應用程序將打開下一個模式。如果用戶單擊取消,則執行「拒絕」並關閉所有Modals。 – Michael