0

I have an element:

I'd like to use

ng-class="{ 'children'+level.length }" (or something like this, i.e to output a class that has the number of levels. Is it possible to do it on this iterating element?

williamsandonz
  • 15,864
  • 23
  • 100
  • 186

2 Answers2

1

Yes, something like:

<div ng-repeat="level in levels">
    <p ng-class="{'children' : level.length == 1}">test</p>
</div>

ng-class simply takes an expression.

tymeJV
  • 103,943
  • 14
  • 161
  • 157
0

I think the easiest way is to use a function in your ng-class.

  $scope.levelClass = function(i){
      return "level"+i;
  }

and then

ng-class="levelClass(children.level)"

Check out this question for other solutions Generating variable for ng-class dynamically using Expression in AngularJs

Community
  • 1
  • 1
NicolasMoise
  • 7,261
  • 10
  • 44
  • 65