1
I have a DIV with a style applied via ng-style (because some values are calculated in the controller).
<div ng-repeat="i in getNumber(tiles) track by $index"
ng-click="toggle = !toggle" // => esta linha não funciona
ng-style="tileStyle"></div>
I need to toggle ng-click by changing the ng-style value to another style also set in the controller.
My controller:
angular.module('warmup').controller('BoardController', function($scope) {
$scope.tiles = 144;
$scope.getNumber = function(num) {
return new Array(num);
}
var boardHeight = window.innerHeight/3;
var boardWidth = boardHeight;
var tileHeight = boardHeight/12 - .3;
var tileWidth = tileHeight;
$scope.boardStyle = {
"height" : boardHeight + 'px',
"width" : boardWidth + 'px',
"border" : "1px solid #AAA"
}
var colors = [
{name: "principal", color: "red"},
{name: "locker", color: "blue"},
{name: "path", color: "green"}
];
$scope.tileStyle = {
"height" : tileHeight + 'px',
"width" : tileWidth + 'px',
"border" : "1px solid #CCC",
"background-color": colors[0].color,
"float": "left"
}
$scope.lockStyle = {
"height" : tileHeight + 'px',
"width" : tileWidth + 'px',
"border" : "1px solid #CCC",
"background-color": colors[1].color,
"float": "left"
}
//esta é a função que tentei escrever, sem sucesso
$scope.toggle = function() {
tileStyle = !lockStyle;
}
});
I found several examples using ng-class. But I can’t use variables in css, and the project doesn’t allow using SASS or LESS.
If you have several Iles for this correct
– novic
Yes, there are several colors. And the color change needs to occur in each one individually.
– Atoyansk