I have some set of code which I want to execute once a function gets completed and this set of steps and functions will be called on click of a button. Below is my code:
$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;
});
};
and my showLoader
function is as below:
function showLoader() {
var dfd = $.Deferred();
$('body').append('<div class="loader"></div>');
dfd.promise();
}
but here alert('next')
gets executed first and then alert('done')
gets executed. What is the actual problem here? I am not pretty much sure about the way the promises work here!! Can anybody tell how to correct this?