angular - 如何在我的页面加载/卸载时实现淡入/淡出效果?

标签 angular angular2-router3

我想我已经连接了基本的动画部分,我只需要知道要处理什么事件。理想情况下,我想要一个可以在导航级别使用的解决方案,这样我就可以包装我的所有组件,但是一个简单的页面加载示例就足够了,我们将不胜感激。 我在 SO 上发现了其他几个相关的问题,但它们似乎没有回答我的具体问题或已过时:

Angular 2 "slide in animation" of a routed component Page transition animations with Angular 2.0 router and component interface promises

这是我目前所拥有的:

html文件

<article @heroState="componentState">
           <p>article element should fade in/out</p>
</article>

组件

@Component({
    selector: 'blog-about',
    templateUrl: './app/about/about.html',
    animations: [
        trigger('heroState', [
            state('active', style({
                backgroundColor: 'blue',
                transform: 'scale(1)'
            })),
            state('inactive', style({
                backgroundColor: 'green',
                transform: 'scale(1.1)'
            })),
            transition('active => inactive', animate('1000ms ease-in')),
            transition('inactive => active', animate('1000ms ease-out'))
        ])
    ]
})
export class About implements OnInit, OnDestroy {
    public componentState: string;
    public Title: string

    constructor() {
        this.Title = "this is about";
    }

    ngOnInit()
    {
        this.componentState = 'inactive';
    }

    ngOnDestroy()
    {

    }
}

最佳答案

你确定你没有引用答案: https://stackoverflow.com/a/40077108/6678754 与 plunker:https://embed.plnkr.co/Vral6cwlaQz27MUQNkVg/ ? 这应该对您有用,请再次检查。

不过您还有另一种选择:在导入 about 组件的父级中使用动画,如下所示:

<blog-about [@heroState]="activeRouteVar"></blog-about>

关于angular - 如何在我的页面加载/卸载时实现淡入/淡出效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38725258/

相关文章:

javascript - 获取给定半径内以及给定纬度和经度(以米为单位)的纬度和经度

javascript - 为什么更改数组的副本会影响原始数组?

angular - 我是否必须取消订阅 ActivatedRoute(例如 params)可观察量?

angular - 错误: No component factory found for TermsConditions

angularjs - 将数据传递到 Angular1 应用程序中降级的 Angular2 组件

javascript - Angular2 解析 Promise 时出错 : Type 'Promise<Hero[]>' is no t assignable to type 'Hero[]'

angular - 如何在 Mat 表中每一行的按钮单击事件下设置对话框的位置?

带有 ngrx 的 Angular 2 router v3 observable guard

angular - 如何在angular2 router3中为子路由指定辅助组件