Javascript 角坐标系中的链式模态
我有以下模板,其中有4个类似模态(只是id不同): ` 我的要求: 如果一个特定的cookie不可用,并且用户没有“取消”之前的任何一个模态,我希望显示4个模态(当用户单击“确定”时一个接一个) 但是我不能把情态动词连起来Javascript 角坐标系中的链式模态,javascript,angularjs,Javascript,Angularjs,我有以下模板,其中有4个类似模态(只是id不同): ` 我的要求: 如果一个特定的cookie不可用,并且用户没有“取消”之前的任何一个模态,我希望显示4个模态(当用户单击“确定”时一个接一个) 但是我不能把情态动词连起来 如何链接模态,以便前一个模态打开另一个模态,直到不满足某个条件?您可以使用一个实用功能来减少键入: function showModal(templateUrl){ return $modal.open({ templateUrl: templateUrl,
如何链接模态,以便前一个模态打开另一个模态,直到不满足某个条件?您可以使用一个实用功能来减少键入:
function showModal(templateUrl){
return $modal.open({
templateUrl: templateUrl,
controller: ModalInstanceCtrl,
resolve: {
items: function () {
return $scope.items;
}
};
}
}
然后像这样使用它:
showModal('template1.html')
.then(function(selectedItemFromTemplate1){
return showModal('template2.html');
})
.then(function(selectedItemFromTemplate2){
return showModal('template3.html');
})
.then(function(selectedItemFromTemplate3){
return showModal('template4.html');
})
.catch(function(reason){
console.log('did not go through all steps because ' + reason);
})
.then(function(selectedItemFromTemplate4){
console.log('finished');
});
一个新的模式而不是上一个,或者上一个模式之上的新模式?显示的代码是直接来自模式文档演示的代码。它没有显示任何打开其他模式的尝试。围绕模态初始化代码创建一个工厂函数,并传入步骤信息,以便您可以在结果回调中更改模板和逻辑。您可以使用promises
$q
链接多个模态。如果用户单击“确定”,您将执行一个resolve
,应用程序将打开下一个模式。如果用户单击“取消”,您将执行一个拒绝
,并关闭所有模态。我认为最好使用一个向导。类似这样:他不能在modalInstance.result中调用$scope.open()(cookie!=可用)吗?我描述了他如何链接模态。当然,上面的示例代码可以适应他想要包含的任何业务逻辑。他甚至可以在任何时候抛出一个异常来取消链接。
function showModal(templateUrl){
return $modal.open({
templateUrl: templateUrl,
controller: ModalInstanceCtrl,
resolve: {
items: function () {
return $scope.items;
}
};
}
}
showModal('template1.html')
.then(function(selectedItemFromTemplate1){
return showModal('template2.html');
})
.then(function(selectedItemFromTemplate2){
return showModal('template3.html');
})
.then(function(selectedItemFromTemplate3){
return showModal('template4.html');
})
.catch(function(reason){
console.log('did not go through all steps because ' + reason);
})
.then(function(selectedItemFromTemplate4){
console.log('finished');
});