Is there a way to create a different background color for each list item using Ionic? For instance, if the list includes fruits like banana, apple, and orange, can we set the background color to yellow for banana, green for apple, and so on?
I've attempted to use ng-style and ng-class but haven't been successful in achieving the desired outcome. I am using collection-repeat for the list.
Any suggestions on how to accomplish this would be greatly appreciated!
EDIT:
http://plnkr.co/edit/L80IcehgBQTiVXCCLWo9?p=preview
HTML
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js?4"></script>
<script src="script.js"></script>
<link rel="stylesheet" href="http://code.ionicframework.com/nightly/css/ionic.css">
</head>
<body ng-controller="MainCtrl as main">
<ion-header-bar class="bar-positive">
<h1 class="title">1000 Items</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item collection-repeat="item in main.items" ng-class="item == '0' ? 'classA' ">
{{item}}
</ion-item>
</ion-list>
</ion-content>
</body>
</html>
JS
var myApp = angular.module('myApp', ['ionic']);
myApp.controller('MainCtrl', function() {
this.items = [];
for (var i = 0; i < 1000; i++) this.items.push(i);
});
CSS
.classA {
background-color: black;
}