Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Diferent background colors for every item on list

$
0
0

@Sidaphextwin wrote:

Hi, I have an array of colors:

var colorsArray = ["red", "blue", "black" ... ];

I get some data of mysql database using http.get and list this data via ng-repeat directive:

<ion-list>
     <ion-item ng-style="getBackColor()" ng-repeat="user in users">
          <h2>{{user.display_name}}</h2>`
          ...

On my app.js I get:

var colorsArray = ["red", "blue", "black" ... ];
var backColor = -1;

$scope.getBackColor = function() {
     backColor++;

     if(backColor > 4) {
          backColor = 0;
     }

     return { 'background-color': colorsArray[backColor] };
}

My code work but I see errors in the log.

I search for a way to create a list with indeterminated number of items and I like paint the list items with diferents background colors. In the array I have a five colours, I like paint the 6th item with first colour of the array.

I have 5 rows in database to show in list, but when I show via console.log(backColor); I get more of five results until a error appear.

Can help me?

Thank you!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>