Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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;

}
share|improve this question
    
Seems like ng-style is better suited for this –  Neps Mar 31 at 20:51

1 Answer 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}">
share|improve this answer
    
still not getting what I want, I need to change the color of background of ".despesas_interna a.status:before" dynamically –  Stack two Apr 1 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.