6

I want to use the background color from my json array, but this does not work.

<td ng-repeat="menus in $scope.menuList">
    <button class="head-button" style="background-color:{{menus.color}}" ui-sref="{{menus.link}}">
        <md-icon>{{menus.icon}}</md-icon>
        <md-tooltip md-direction="top">{{menus.tooltip}}</md-tooltip>
        <div class="head-mini-text">{{menus.text}}</div>
    </button>
</td>

How come that style="background-color:{{menus.color}}" is not working? Is there a better way to do this?

2

1 Answer 1

8

You can use angular directive ng-style to dynamically change the color of your background

HTML:

 <button class="head-button" ng-style="{'background-color':menus.color}" ui-sref="{{menus.link}}">

For more reference: https://docs.angularjs.org/api/ng/directive/ngStyle

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

Comments

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.