【发布时间】:2017-09-03 09:58:33
【问题描述】:
而不是像this StackOverflow answer 或first part of the official documentation 那样将动画附加到被路由到的每个组件。一个例子:
在
hero-detail.component.ts:import { Component, OnInit } from '@angular/core'; import { fadeInOutAnimation } from "app/app-routing.animation"; @Component({ selector: 'app-home', templateUrl: './home.component.html', animations: [ fadeInOutAnimation(300) ] }) export class HomeComponent{ }在
app-routing.animation.ts:import { trigger, state, style, animate, transition } from '@angular/animations'; export const fadeInOutAnimation = function (fadeInTimeMS) { return trigger('fadeInOut', [ transition(':enter', [ // :enter is alias to 'void => *' style({ opacity: 0 }), animate(fadeInTimeMS, style({ opacity: 1 })) ]), transition(':leave', [ // :leave is alias to '* => void' animate(fadeInTimeMS, style({ opacity: 0 })) ]) ]) }
我想根据路线路径为路线制作动画:
将路线动画应用于单个组件适用于一个简单的演示,但在现实生活中的应用程序中,最好根据路线路径为路线设置动画。
如角度文档中'Adding animations to the routed component' 末尾所述。但它没有详细说明如何执行此操作。
【问题讨论】:
-
这里有一个Angular v4的例子:github.com/matsko/ng4-animations-preview/blob/master/src/app/…
-
他们的指南充满了可疑的建议和类似的陈述。它变化如此之快,以至于您可以在几行之间找到相互矛盾的信息。如果有一些关于基于路线路径动画路线的信息,那就太好了。也许在“动画”部分或“路由”部分。
标签: javascript angular animation