Angular performs a digest function to update the DOM when your data changes.
During the digest, it recomputes all the values you have bound in the DOM, in this case {{RandomColorClass()}}
. If any of them change, it again performs a digest cycle (since some variables may depend on the value of of the changed variable, for example).
It does this repeatedly until two digests in a row result in the same values -- i.e, nothing has changed.
What's happening is that when a digest occurs, your RandomColorClass()
function is being called and returns a different value. This triggers an additional digest, where RandomColorClass()
again returns a different value, which triggers another digest...
Can you see where this is going? You shouldn't be generating random values in this manner -- instead, generate them in your scope and persist them.
One approach might be, in your scope:
function randomColourClass() { /* ... */ };
$scope.GridStockRecords.forEach(function(record) {
record.colorClass = randomColourClass();
});
and HTML:
<div ng-repeat="stockRecord in GridStockRecords | filter:searchText"
ng-class="stockRecord.colorClass">
<div>
<h6>{{stockRecord.ProductGroupName}}</h6>
</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…