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 ?

Vaibhav Jain
  • 3,729
  • 3
  • 25
  • 42

1 Answers1

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.

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234