【发布时间】:2015-08-07 19:48:11
【问题描述】:
我有一些代码,我想在函数完成后执行这些代码,单击按钮将调用这组步骤和函数。以下是我的代码:
$scope.activetab = function (tabname, $event) {
$.when(function () {
showLoader();
alert('done');
}).done(function () {
alert('next');
if (tabname == 'General')
$scope.GeneralAct = true;
else if (tabname == 'Contact Information')
$scope.ContactAct = true;
else if (tabname == 'Position/Hierarchy')
$scope.PositionAct = true;
else if (tabname == 'Ids and Program Access')
$scope.IdsAct = true;
else if (tabname == 'Equipment')
$scope.EquipmentAct = true;
else if (tabname == 'Licensing')
$scope.LicensingAct = true;
});
};
我的showLoader函数如下:
function showLoader() {
var dfd = $.Deferred();
$('body').append('<div class="loader"></div>');
dfd.promise();
}
但是这里alert('next') 先被执行,然后alert('done') 被执行。这里的实际问题是什么?我不太确定承诺在这里的工作方式!谁能告诉我如何纠正这个问题?
【问题讨论】:
标签: javascript jquery angularjs promise