[英]Showing multiple modals in a loop
I'm using Angular UI Modals ( http://angular-ui.github.io/bootstrap/#modal ) 我正在使用Angular UI Modals( http://angular-ui.github.io/bootstrap/#modal )
I have to show the same modal, multiple times in a loop. 我必须在循环中多次显示相同的模态。
For example I have a team, and I need to show the edit team member modal for each person in succession (basically it's a wizard) 例如,我有一个团队,我需要连续显示每个人的编辑团队成员模态(基本上是向导)
The problem I have is that it opens ALL the modals, stacked on top of each other, and I'd like to get them to open one at a time. 我的问题是,它会打开所有堆叠在一起的模态,我想让它们一次打开一个模态。
for (var i = 0; i < team.SizeLimit; i++) {
var participant = { }; // assume this hold the correct participant
var openModal = $modal.open({
templateUrl: '/Modals/Participant/Edit.html',
backdrop: true,
windowClass: 'modal',
controller: 'ModalParticipantController',
resolve: {
title: function () { return 'Edit Participant'; },
participant: function () { return participant; }
}
});
openModal.result.then(function (data) {
alert('success!');
});
}
How can I get it to open these in succession, as the modals are closed, one at a time? 如何关闭模态,一次一次打开它们?
I'm not an angularJs user, but i had this same problem a while back. 我不是angularJs用户,但不久前我遇到了同样的问题。
instead of creating the modals in a loop, you create a loop with the modals itself where you check the next participant when you close the current modal. 而不是在循环中创建模态,而是使用模态本身创建一个循环,在关闭当前模态时在其中检查下一个参与者。 (i'm guessing openModal.result.then() is the callback for that)
(我猜openModal.result.then()是它的回调)
var fnOpenModal = function(i) {
if (i >= team.sizeLimit)
return;
var participant = team[i],
openModal = $modal.open({
....
});
openModal.result.then(function (data) {
alert('success!');
fnOpenModal(i + 1);
});
}
fnOpenModal(0);
it's definetly not the best solution, but it's a quick one that works :-) 绝对不是最好的解决方案,但它是一种可行的快速解决方案:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.