Reputation: 295
I need set a custom style of dynamics div. Div are conforms to the balise :
<div class="row">
<div id={{'letter'+$index}} ng-style="{{theStyle}}" class="col"
ng-repeat="letter in letters track by $index">{{letter}}
</div>
</div>
The color of each letter must be defined in function of a level and by the value of the index that are declared in an array. I have three levels (low, medium, high), so the low-style, the medium-style and the high-style. The array can be for example: ['color': 'white', 'border-color': 'blue', ..., 'color': 'white', 'border-color': 'red']. For each letter there are an element of the array.
Could you suggest a smart solution for this case ?
Thanks
EDIT: The variables used in the controller are:
var word = getWord(objectWord, getLanguage());
$scope.letters = word.split('');
$scope.level = getLevelCSS(getLevel());
var arrStyles = getStyles(letters.length);
Upvotes: 0
Views: 629
Reputation: 594
You could pass your ng-style a directive function like this
<div ng-style="changetheColor(style-level, colorinfo)" colordirective></div>
And the directive would look smth like this
.directive('colordirective', function (Ls) {
return function (scope, element, attr) {
scope.changetheColor = function (level, color) {
if(level == 'medium'){
return color;
}else if(level == 'high'){
return color;
}
}
}
})
If u want u can pass the Level and the style info from the array and return it in the directive
Upvotes: 1