In my application I've tabs which loads form in each tab with certain amount of controls in it! Some tab will have huge number of controls and some might have less. So what I was trying to achieve is to show a loader when contents are being rendered into html. These contents will always be loaded at page load but rendering happens only when the tab is clicked. See the below code!
$scope.activetab = function (tabname) {
showLoader();
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;
};
function showLoader()
{
$('body').append('<div class="loader"></div>');
}
What is happening is showLoader does not work until the render gets completed.
Now when I put alert after showLoader it will fire and loader will be shown. What I feel is the alert stops current execution of code and waits for user response for the alert and it'll render whatever has been executed until then! So is there any work around so that I can show the loader which does not wait for other html contents to render?
What I have tried so far?
- Tried returning a
promisefromshowLoaderfunction and tried to wrap theif elsecode in$.whenand.thenfunctionality. - Tried keeping
<div class='loader'></div>in body instead of appending it everytime and tried totoggleorfadeIn/fadeOutit inshowLoader. - Tried keeping
if elseinsetTimeOutto execute it after some fraction of seconds.
But unfortunately all the results returned with no success! If any workaround to show the loader is there, then I will be gladful to implement it!