0

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);
1
  • Can you add arrays/object you are working with? What you posted is not valid. Post letters array. Commented Jun 30, 2015 at 10:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Could you be more specific about ? Thanks
well the changetheColor function is called for every element which has "colordirective" so when u for example ng-repeat over some array every element gets the color depending on the "style-level" (medium - high....)
you said every letter has an array element so basicly every letter would get a different color depending on the level in my example medium would be green and high would be red
I need pass the level info and the array of styles. Both parameters are important for me
i just changed my answer so u need to pass the level and the colorinfo to the directive function and there u just return the colorinfo depending on the style-level

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.