4

Here is the Link for the jsFiddle : AngularJS : Display Data

I have HTML File is like following:

<div ng-controller="myCtrl">         
    <div ng-repeat="test in tests">
           <p>{{test.testName}}</p>
    </div>
</div>

Controller under .js file is like following:

var app = angular.module('myApp', []);

function myCtrl($scope) {
    $scope.tests = [{
        "testName" : "Test-1 : Windows Test"
        }, 
        {
        "testName" : "Test-2 : Linux Test"
        },          
        {
        "testName" : "Test-3 : Unix Test"
        }, 
    ];
}

My Question is:

Currently the result is coming in the following format:

Test-1 : Windows Test
Test-2 : Linux Test
Test-3 : Unix Test

I want to display the Test-1 : Windows Test at beginning and after 30 seconds Test-2 : Linux Test and after 30 seconds Test-3 : Unix Test and so on..!!

Once all the data are completed again the Test-1 : Windows Test will come again..!!

How should I implement this with the AngularJS ?

2
  • 1
    you may need to use ngAnimate with $interval Commented Apr 16, 2015 at 10:40
  • @pankajparkar , You are correct. and OP please see my answer. i hopes my answer will solve your problem ;) Commented Apr 16, 2015 at 11:05

1 Answer 1

3

You can do it by using set time interval ( $interval in angular.js) . I don't know how can i explain to you. But i will give my code with fiddler, You can see what i am did.

So try this below way instead of your code.

<div ng-app="myApp">
<div ng-controller="myCtrl">
   <p>{{testName}}</p>
</div>
</div>

Javascript changes

The below code working by eache 30 second( i don't know exactly 30 second), But you can put what time you need

    angular.module('myApp',[])
   .controller("myCtrl",["$scope","$interval",function($scope, $interval){
        $scope.tests = [{
            "testName" : "Test-1 : Windows Test"
            }, 
            {
            "testName" : "Test-2 : Linux Test"
            },          
            {
            "testName" : "Test-3 : Unix Test"
            } 
        ];
         var count=0;                    
         $interval(function(){                         
                $scope.testName=$scope.tests[count].testName;
                 count=count+1;
                if($scope.tests.length==count){
                  count=0;
                }                               
         },30000);   // I don't know it's exact 30 seconds     
    }]);

Sample JSFiddle Demo

I have updating proper code for you.

Sign up to request clarification or add additional context in comments.

2 Comments

can you please update your code to use app.controller which would be the more correct way of doing code
Okay wait few seconds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.