Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I have this JSON object that contains an array of devices types and each type has an array of brands:

{
"types": [
    {
      "type": "phone",
      "brands": [“samsung”,”apple”,”LG”, … //a list of brands]
    },
    {"type": "PC",
      "brands": [“DELL”,”apple”,”HP”, … //a list of brands]
    },
    …// a list of types
]

}

Using AngularJS ng-repeat I can iterate through every array , but I want to show the list of brands one by one in the same button , every value is shown for 2 seconds , in infinite loop, but I can’t figure out a way to do that.

share|improve this question
1  
increase a counter on every 2 seconds, may be with $timeout, and show that with types[count % types.length], without ng-repeat. –  YOU Sep 3 at 10:44
1  
you can do it with $interval –  entre Sep 3 at 11:01
    
@entre, yes, i wanted to say interval, but typed timeout, thank you. –  YOU Sep 3 at 11:06

2 Answers 2

you dont need ng-repeat for this. given that you need to display only one element at a time.

vm.display = {
   count : 0,
   current :  null,
   repeat : function() { $interval( vm.display.changeElement(), 2*1000)  }
   changeElement : function() { vm.display.current =  list[vm.display.count] ; vm.display.count++; }
}

then just call vm.repeat() after getting data from server

share|improve this answer
    
It works thank you , I adjusted it to my data , but my web page seems to be a little slow , because i have too many data to show in the same way, is there any way to make it faster ? –  tahayk Sep 3 at 15:23
    
Use pagination to get the data from server –  entre Sep 3 at 17:27
    
can you please accept the answer –  entre Sep 4 at 6:40

As mentioned earlier, you can use $interval instead of ng-repeat to do this.

$interval(function(){
      $scope.buttonLabel =$scope.data.types[0].brands[$scope.count%3];
      $scope.count++;
    },2000);

I hope this is what you need. :) http://plnkr.co/edit/8VIJAN?p=preview

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.