这个问题在这里已有答案:
我试图创建一个自举轮播 . 所以我使用* ngFor添加元素和轮播指示符 . (指示当前位置的小圆圈)
<li data-target="#myCarousel" *ngFor="#item of items; #idx = index" data-slide-to="idx" [class.active]="idx === 0" >
我通过[class.active] =“idx === 0”设置活动类条目,它工作正常 . 但是当我试图设置data-slide-to =“idx”时,结果不是想要的索引作为数字而是字符串“idx” .
知道如何分配索引值吗?
2 回答
你有两个选择:
1. Bind directly to the attribute
2. Use string interpolation
绑定需要
[]
或{{}}
. 绑定到属性需要attr.
前缀