I'm trying to add class x and then class y to an element in an angular service/directive (it must be in a script and not via ng-class). the sequence is critical - I want x to be added first and only then y - it needs to be 2 steps.
I was sure this would work:
$(element).addClass('x');
$timeout(function () {
$(element).addClass('y');
},0)
But it turns out that sometimes it is not consistant and that y is being added before x. I thought $timeout
will garauntee a 2 step process - but I'm asking if there is another way to garauntee it. maybe an 'onload' or 'onupdateClass' event on the DOM element that I don't know if it exists?
Clarification: It is not important if eventually it will be 'x y' or 'y x'. The string order is not important. what is important is the sequence: first add x, wait for it to be added and then add y