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
  • 14,774
  • 21
  • 91
  • 180

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
  • 102,126
  • 13
  • 159
  • 155
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,221
  • 10
  • 43
  • 65