AngularJS - 如何添加多个纳克级的指令?
问题描述:
下面是使用纳克级
指令两种不同的方式。我需要他们两个,在相同的元素,但不起作用。
Here are 2 different ways to use the ng-class
directive. I need them both, on the same element, but that doesn't work.
http://plnkr.co/edit/uZNK7I?p=$p$pview
<div ng-repeat="item in [1, 2, 3, 4, 5]"
ng-class="{ first: $first, last: $last }">{{item}}</div>
正确导致
<div class="first">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div class="last">5</div>
在纳克级使用EX pression
http://plnkr.co/edit/tp6lgR?p=$p$pview
<div ng-repeat="item in [1, 2, 3, 4, 5]"
ng-class=" 'count-' + ($index + 1) ">{{item}}</div>
正确导致
<div class="count-1">1</div>
<div class="count-2">2</div>
<div class="count-3">3</div>
<div class="count-4">4</div>
<div class="count-5">5</div>
现在,如何一起使用它们?
我需要动态类的名称(如'count-'+ N
),但还需要多个类对象的语法。
Now, how about use them together?
I need dynamic class names (like 'count-' + n
), but also need the object syntax for multiple classes.
我不能只用2 纳克级
属性(的 http://plnkr.co/edit/OLaYke?p=$p$pview ),只有第一个作品。
I can't just use 2 ng-class
attributes (http://plnkr.co/edit/OLaYke?p=preview), only the first one works.
有什么建议?
答
您不应该使用纳克级
第二,可以用
You shouldn't be using ng-class
for the second one, use
<div class="count-{{$index + 1}}" ng-class="{ first: $first, last: $last }">