[英]Issue with the $mdDialog.show(confirm), not able to execute the code below this dialog directives in 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 }
它可能不像您想要的那樣漂亮,但是可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.