Agregue una clase selectivamente a un ng-repeat AngularJS
Tengo una repetición ng para una tabla, quiero poder agregar una clase cuando<td>
se hace clic y elimina la clase cuando no se hace clic. Múltiple<td>
Se puede seleccionar al mismo tiempo. En este momento, TODAS las ciudades reciben o no la clase se aplica.
Por ejemplo: (digamos que los nodos tienen 100 elementos)
<tr ng-repeat node in nodes>
<td>{{node.name}}</td>
<td>{{node.date}}</td>
<td ng-click="toggleMe( node.city )" ng-class"{clicked : isClicked()}" >{{node.city}}</td>
</tr>
en mi JS
$scope.cityArr = [];
$scope.toggleMe = function(city) {
if ($scope.count > 0) {
angular.forEach($scope.cityArr, function(value) {
if (city === value) {
$scope.clicked = false;
} else {
$scope.cityArr.push(city);
$scope.clicked = true;
}
});
} else {
$scope.cityArr.push(city);
$scope.clicked = true;
}
$scope.count = 1;
};
$scope.isClicked = function() {
return $scope.clicked;
};