使用* ngFor索引来计算动画延迟

时间:2018-09-05 11:39:43

标签: css angular angular5 ngfor

似乎是this问题的重复,但实际上我是在尝试影响test = InputBox("Enter a value") If StrPtr(test) = 0 Then MsgBox "Cancel" ElseIf Len(test) = 0 Then MsgBox "No entry" Else MsgBox "Correct" End If 属性,而不是动画定时本身。

我有一个Angular模板,它通过遍历列表项来创建列表项:

animation-delay

如您所见,我已经有了索引,并希望使用它来增加每个元素上的动画延迟。但是,当我在chrome中进行测试时,即使index属性正确应用,样式属性甚至都无法计算。我在CSS中指定的动画效果很好,但没有应用延迟:

<div class="list-item" *ngFor="let item of items; let i = index" [attr.data-index]="i" style="animation-delay: {{ (i) + 's' }}"></div>

1 个答案:

答案 0 :(得分:3)

尝试使用ngStyle指令:

[ngStyle]="{'animation-delay': i + 's'}"

希望效果很好,否则请在stackblitz上分享一个工作示例

相关问题