Loop through li - Fade In / Fade Out - repeat - Using Angularjs

I have just started using Angularjs.... I have created a simple polling script to pull data from a php script.

discussionApp.controller('ViewCtrl', function($scope, $timeout, $http /* , $location,  */) {
    console.log("View Controller");
    $scope.pageClass = 'page-view';


   
    $scope.contents = [];
    lastID = "0";


        var getData = function() {
            $http.post('getData.php?id='+lastID)
            .success(function(data, status) {
                //$scope.contents = data;

                if (data != undefined) {
                    Array.prototype.push.apply($scope.contents, data);

                    lastID = $scope.contents[$scope.contents.length - 1].discussionID;
                    console.log("LAST ID: "+lastID);
                }
            })
            .error(function (data, status) {
                console.log("ERROR: "+status)
                $scope.status = status;
            });

            $timeout(function() {
                $scope.value++;
                getData();
            }, 50000);

            //showNextImage();
        };

        //Start function getData()
        getData();


});

Open in new window



Currently the data gets listed on the screen

      <div>
        <ul id="allImages">
          <li ng-repeat="content in contents" class="{{content.discussionID}} images">
            {{content.discussionID}} - {{content.discussionName}} - {{content.discussionText}}
          </li>
        </ul>
      </div>

Open in new window


I would like to create a function that fades in one li ... waits 2 seconds ... then fades out.
Once it gets the end of the list, start again.
Steve TinsleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Have you read the Angular documentation on ngAnimate?

https://docs.angularjs.org/api/ngAnimate

Start there.
0
Steve TinsleyAuthor Commented:
I have seen that.... but I thought it may be better to do it in the controller....

I have managed to get something working... with a lot of trial and error.
What do you think?
The end solution could have an image list array of several 100 images... being added to all the time.


/**
 * Controls the View
 */
discussionApp.controller('ViewCtrl', function($scope, $timeout, $http /* , $location,  */) {
    console.log("View Controller");
    $scope.pageClass = 'page-view';


    $scope.contents = [];
    $scope.images = [];
    
    var lastID = "0";

        var getData = function() {
            $http.post('getData.php?id='+lastID)
            .success(function(data, status) {
                //$scope.contents = data;

                if(data.length > 0){  
                    Array.prototype.push.apply($scope.contents, data);
                    Array.prototype.push.apply($scope.images, data);

                    lastID = $scope.contents[$scope.contents.length - 1].discussionID;
                    console.log("LAST ID: "+lastID);

                    imageLoop( $scope, $timeout ); //Redraw imageLoop

                }
            })
            .error(function (data, status) {
                console.log("ERROR: "+status)
                $scope.status = status;
            });

            $timeout(function() {
                $scope.value++;
                getData();
            }, 500);


        };

        //Start function getData()
        getData();



    function imageLoop( $scope, $timeout ) {
        var update;

            clearTimeout(update);
            console.log("clear");
            $scope.imgIndex = 0;

            update = $timeout(function advanceImage() {
                console.log($scope.images.length);
                $scope.imgIndex = ($scope.imgIndex + 1) % $scope.images.length; 
                $timeout(advanceImage, 1000);
            })
    
    }





});

Open in new window

0
Julian HansenCommented:
but I thought it may be better to do it in the controller....
No, definitely not in the controller.
All posts I have read suggest this is a bad idea and a directive should be used instead.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve TinsleyAuthor Commented:
Would you be able to give an example? Im very new to this.
0
Julian HansenCommented:
I can't do anything right now - I am on the road - my advice is to Google ngAnimate there should be many examples out there.

If you don't come right post back and I will pick up when I am back.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.