[英]angular2-counto inside *ngFor
I'm trying to use the angular2-counto
directive inside an *ngFor
loop. 我正在尝试在
*ngFor
循环中使用angular2-counto
指令。
I know that I need a unique string in each instance. 我知道每个实例都需要一个唯一的字符串。 So
所以
<div
counto
[step]="30"
[countTo]="myArr[0].Amount"
[countFrom]="0"
[duration]="2"
(countoChange)="counto_0 = $event"
(countoEnd)="onCountoEnd()">
{{counto_0 | number:'1.0-0'}}
</div>
<div
counto
[step]="30"
[countTo]="myArr[1].Amount"
[countFrom]="0"
[duration]="2"
(countoChange)="counto_1 = $event"
(countoEnd)="onCountoEnd()">
{{counto_1 | number:'1.0-0'}}
</div>
...
Should become 应该成为
<div *ngFor="let item of myArr"
counto
[step]="30"
[countTo]="item.Amount"
[countFrom]="0"
[duration]="2"
(countoChange)="??? = $event"
(countoEnd)="onCountoEnd()">
{{??? | number:'1.0-0'}}
</div>
But what can I use in the ???
但是我可以在
???
使用什么呢???
as a unique param for each iteration of the loop? 作为循环的每次迭代的唯一参数? The
counto
directive needs a string param (I think). counto
指令需要一个字符串参数(我认为)。 Attempts to use *ngFor=let i item of myArr; let i = index;
尝试使用
*ngFor=let i item of myArr; let i = index;
*ngFor=let i item of myArr; let i = index;
and then somehow use the index in the directive don't work. 然后以某种方式在指令中使用索引不起作用。
<div *ngFor="let item of myArr; let i = index;"
counto
[step]="30"
[countTo]="item.Amount"
[countFrom]="0"
[duration]="2"
(countoChange)="i = $event"
(countoEnd)="onCountoEnd()">
{{i | number:'1.0-0'}}
</div>
Results in Uncaught Error: Cannot assign to a reference or variable!
导致
Uncaught Error: Cannot assign to a reference or variable!
You are trying to assign $event
to the i
variável. 您正在试图分配
$event
给i
variável。 Try something like: 尝试类似:
newVar[i] = $event
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.