c# - $mdDialog.show(confirm) 的问题,无法在 AngularJS 中执行此对话框指令下方的代码
问题描述
我发现这个问题$mdDialog.show(confirm)
,对话框函数下面的代码甚至在弹出窗口出现之前就执行了。
我可以通过设置一个标志来限制下面代码的执行。但是在对话活动完成后,它会在Error(ie, resolvePromise())
不执行以下代码的情况下进入:
//This is the code I have used.
var confirm = $mdDialog.confirm()
.title('Early Dispatch Date Available.')
.textContent('Do you want to reschedule and Change Quantity.')
.ariaLabel('day')
.ok('Yes')
.cancel('Plan on Date');
$mdDialog.show(confirm).then(function (obj)
{
$scope.targetDates[lastItem].Qty = 0;
return;
}, function () {
condition = 'QtyLessThanCap';
});
//for example,this is the code which gets executed even before the comfirmation dialog pops up..
angular.forEach($scope.targetDates, function (Datess)
{
totalCalQty = totalCalQty + parseInt(Datess['Qty']);
});
我希望代码按照我编码的顺序执行,我的意思是下面的代码只需要在确认对话框活动之后执行。
先感谢您。
解决方案
我能够处理相同类型的功能的唯一方法是拆分函数,例如,您有一个动作函数来确定您是需要模态还是可以计算总数:
function something() { // if modal show modal.then(doSomething) }
然后是可以直接调用的实际计算函数,也可以从任何级别的 mdModal.then() 调用:
function doSomething() { // calculate total }
它可能不像你想要的那么漂亮,但它确实有效。
推荐阅读
- qt - 获取 ProgressBar 以填充 Rectangle qml
- google-sheets - 我如何与列进行比较并自动返回一个数字:示例:=IFS(AND(B2="Groups",N2="Blood Donation"),4)
- xml - 第 x 行的 xml 解析错误。文档末尾的额外内容
- c - 找不到 gtkbuilder.c 的日志域名
- python - 返回所有单个字母的集合,而不是每个单词的集合
- javascript - 如何在iOS中停止双击缩放整个页面
- javascript - 在另一个函数中使用一个函数 - javascript
- powershell - 在 PowerShell 中使用 Test-Connection 时如何返回布尔值和 TestConnectionCommand+PingStatus?
- laravel - 使用 if/else 运算符的 Laravel 查询
- java - 将 2 个不同大小的二维数组加在一起