1
I am making a web game with different levels and need to change the style of a div using a code saved within an array in Angularjs. In addition, the game has a split on the screen, where in one half the user enters the code and in the other, appears the result. Each level has a different style for the background view, so it needs to be loaded every time.
The HTML file part is as follows:
<div id="background"></div>
And the code referring to the style is as follows:
$scope.css = [
{
'estilo': 'background-image : url(...); ...'
}
];
Another tested form already:
$scope.css = [
{
//nível 1
'background-image': 'url(...)',
'position' : 'absolute',
...
},
{
//nível 2
...
}
];
However I am not able to display the result in the view. Nothing appears. I tried to add ng-style="{{css}}"
à div but it didn’t work. What is the correct way to do this style assignment?
Mine was just the place where I inserted the
ng-controller
. It’s working perfectly, thanks for the help. Anyway, I managed to do it this way:ng-class="{'level-one': cur_level == '1', 'level-two': cur_level == '2', 'level-three': cur_level == '3'}
– Mateus Rocha