1

I'm trying to change the background color of a class dynamically, the color that I have to use comes from an API. I'm using a pseudo-element because what I want to achieve is like this

  <div class="despesas_interna">


                    <a ng-class="{'status ': style(despesa.categoria_cor)}">

                        {{despesa.data | amDateFormat:"DD/MM/YYYY"}}
                        <span>{{despesa.categoria_nome}}
                        <i class="ion-ios-arrow-right despesas_arrow"></i>
                        </span>

                        <p>

                            {{despesa.valor | moneyFormatBR}}
                            <span> </span></p>
                    </a>

                </div>

Controller:

 $scope.style = function(value) {
            return { "background-color": value };
        }

CSS:

.despesas_interna {

    padding: 10px 10px 10px 15px;
    font-weight: normal;
    font-size: 15px;

}

.despesas_interna a:before {
    content: "";
    display: block;
    position: absolute;
    width: 7px;
    left: 0;
    top: 0;
    bottom: 0;

}

.despesas_interna a.status:before {

    background-color: #87c424;

}
1
  • Seems like ng-style is better suited for this Commented Mar 31, 2015 at 20:51

1 Answer 1

1

Use ng-style instead of ng-class. You have two ways to use it:

<div ng-style="style(value)">

and

<div ng-style="{'background-color': value}">
Sign up to request clarification or add additional context in comments.

1 Comment

still not getting what I want, I need to change the color of background of ".despesas_interna a.status:before" dynamically

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.