I want to do simple sequential effects using angularjs. I can do this in jquery, but I just don't know what path to follow to do the same thing using angularjs.
To make things concrete, here is a simple jquery based sequential effect that I would like to create using angularjs. When we click on a tag, the text value of the another tag is sequentially set to each element of an array for a fixed duration. A jsfiddle prototype of this is at
http://jsfiddle.net/mjandrews/U53jy/6/
whose javascript code is
var wordlist = ['A', 'B', 'C', 'D', 'E'];
var duration = 200;
var i = 0;
show_next_word = function () {
if (i < wordlist.length) {
$('#word').hide()
.text(wordlist[i++])
.fadeIn()
.delay(duration)
.fadeOut(show_next_word // recursively call until end of word list
);
} else {
i = 0; // re-set index
}
};
$('#startbutton').click(show_next_word);
To do the same thing in angular, I am frankly not sure even what tree to start barking up.
From my searches so far, I found discussion about chaining promises using the $q service. Is this what I should be thinking about? Can anyone point me to a working example? If this is not the best way to proceed, is something like $animate more appropriate? Is there something else that I should be considering? Any pointers to a better way would be appreciated.
P.s. This question is based on following the advice of this answer that states "And when you come to a problem that you think you know how to solve in jQuery already, before you reach for the $, try to think about how to do it within the confines the AngularJS. If you don't know, ask!" I have a problem that I know how to solve in jquery. I want to do the angular way. I have tried to think about the problem and given my lack of experience with angularjs, I am at a loss and so that's why I am asking.