0

I have an application built with AngularJs.

Html file contain information like that:

<div>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
</div>

So on website I can have 4 different elements. If I have just two of then I want to use different classes then with 4 of them.

   if(myVar == 0){
        $scope.life_class='';
    }else if(myVar ==1){
        $scope.life_class='doscol';
    }else if(myVar ==2){
        $scope.life_class='tricol';
    }else if(myVar ==3){
        $scope.life_class='foucol';
    }else{
        $scope.life_class='fifcol';
    }

And with 'foucol' and 'fifcol' classes I want to add another class, but only in case that 'foucol' and 'fifcol' are in use.

I tried many times with different solutions like that:

if(active_date_count >= 2) {
    document.getElementById("h3").foucol += " font_class";
     document.getElementById("h3").tricol += " font_class";
 }

But it does't work properly. Any ideas? Thanks in advance

1 Answer 1

1

In Angular, you can use ng-class to achieve conditional classes.

<h3 ng-class="{'font_class': condition}" ...></h3>

For more info, see https://docs.angularjs.org/api/ng/directive/ngClass

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.