I am facing an issue with my table rows where cells are being filled with words from an API. I have implemented a feature that allows users to toggle the selection of a cell. To achieve this, I am using ng-class={selected:toggle} and ng-click="toggle = !toggle" in my code.
Markup
<tr ng-repeat="row in game.rows">
<td id="row-{{$parent.$index+1}}-col-{{$index+1}}" ng-repeat="word in row.words" ng-class={selected:toggle} ng-click="toggle = !toggle"><div class="points">{{generateRandomPoints()}}</div>{{word}}</td>
</tr>
In order to assign random points to each cell using a Math function (
<div class="points">{{generateRandomPoints()}}</div>
), I have added the following JavaScript logic:
JavaScript
$scope.generateRandomPoints = function(){
return Math.floor((Math.random()*5)+2);
};
However, I seem to be encountering issues with the toggling functionality because of this Math function. Additionally, each click on a cell results in the regeneration of random numbers through the Math function.
Can anyone provide insights into why the toggling feature is not working as expected?