3
<div id="parent" ng-class="{testClass:???}">
   <span id="child" class="test"/>
</div>

On this example, how would I do it so that if element child would have a class test, the parent element would dynamically have the class testClass?

2
  • Do you control the class of the child? I mean its obviously dynamic in some form but if its not set with ng-class how is it set? Commented Dec 15, 2015 at 8:15
  • Possible duplicate of AngularJS ngClass conditional Commented Dec 15, 2015 at 8:16

2 Answers 2

3

You can create a scope variable to validate whether those 2 elements should be visible or not. The inner span too should be getting set dynamically according to your description. So you can use ng-class for that too. So the code can be like this :

<div id="parent" ng-class="{testClass : isValid}">
    <span id="child" ng-class="{test : isValid}"/>
</div>
Sign up to request clarification or add additional context in comments.

Comments

2

You can add the ternary condition within the ng-class like

var var-test = 'hi'=='bye'
ng-class=" var-test ? 'class-if-true' : 'class-if-false'">

and put in your css file the classes

.class-if-true{color=black}
.class-if-false{color=white}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.