I would like to see the change of values in the array and if a change occurs to compare the old value with the new value, if the old value is greater than the new value to add 'red' class to element.
Controller for each item? This can be inefficient at large array.
How best way to do it?
var app = angular.module('myApp',[])
app.controller('myCtrl', function($scope,DataFactory) {
$scope.items = DataFactory.data;}));
});
app.factory('DataFactory', function($interval){
var data = [
{ 'value' : 1 },
{ 'value' : 2 },
{ 'value' : 3 },
{ 'value' : 4 },
{ 'value' : 5 },
{ 'value' : 6 }
];
var i = 0;
$interval(function(){
i++;
data[3].value = i;
},2000);
return {
data : data
}
});
.block {
width: 50px;
height: 50px;
background: #ccc;
text-align: center;
padding-top:10px;
}
.gren {
background: green;
}
.red {
background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div ng-repeat="item in items" class="block">
{{item.value}}
</div>
</div>
</body>