我为数据创建服务后,动画停止了工作。看起来像是因为当页面最初加载时,ng-repeat中没有元素(因为它正在获取数据)。似乎是THIS和THIS的类似案例:
错误:
ERROR Error: Unable to process animations due to the following failed trigger transitions @listAnimation has failed due to:
- `query(":enter")` returned zero elements. (Use `query(":enter", { optional: true })` if you wish to allow this.)
动画:
trigger('listAnimation', [
transition('* => *', [
query(':enter', style({ opacity: 0}), { optional: true }),
query(':enter', stagger('150ms', [
animate('.5s ease-in', keyframes([
style({ opacity: 0, /*transform: 'translateY(-75px)',*/ offest: 0}),
style({ opacity: .5, /*transform: 'translateY(35px)',*/ offest: .3}),
style({ opacity: 1, /*transform: 'translateY(0px)',*/ offest: 1})
]))
]))
])
])
HTML:
<div [@listAnimation]>
<div *ngFor="let member of members" class="member-card">
member info goes here...
</div>
</div>
现在在你说"put in { optional: true } like the error message says"
之前......我做到了 - 它摆脱了错误信息,但实际上并没有让动画发挥作用:
trigger('listAnimation', [
transition('* => *', [
query(':enter', style({ opacity: 0}), { optional: true }),
query(':enter', stagger('150ms', [
animate('.5s ease-in', keyframes([
style({ opacity: 0, /*transform: 'translateY(-75px)',*/ offest: 0}),
style({ opacity: .5, /*transform: 'translateY(35px)',*/ offest: .3}),
style({ opacity: 1, /*transform: 'translateY(0px)',*/ offest: 1})
]))
]), {optional: true})
])
])
请记住,在从app组件中取出数据之前,这一切都有效。数据就在那里,应用程序正常运行,只是这个动画不再起作用了。
答案 0 :(得分:0)
您必须确保仅在members数组不为空时才显示列表容器。这样,只有当列表中有内容时,动画才会触发。
ApplicationName