【问题标题】:Angular 4 - fade in view on route change using angular animationsAngular 4 - 使用角度动画淡化路线变化
【发布时间】:2018-03-06 12:37:02
【问题描述】:

问题: Angular 4 - 使用角度动画淡化路线变化

问题:

目前,视图在网站的加载中淡出,但在路线更改时不会。 我也希望视图在路线更改时始终淡入。

这是我的 HTML:(可能问题在这里???)

  <div class="page" [@fadeInTransition]>
    <router-outlet></router-outlet>
  </div>

这是我的应用组件:

import { Component, HostBinding  } from "@angular/core";
import { Router, ActivatedRoute } from "@angular/router";
import { MetadataService } from 'ng2-metadata/index';

import { fadeAnimation } from "./animations/fade.animation";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  animations: [fadeAnimation()] 
})

export class AppComponent {
    @HostBinding('@fadeInTransition') fadeInTransition;

    constructor(private route: ActivatedRoute, private router: Router, private metadataService: MetadataService) {
    }
}

这是我的动画(我导入的):

import { trigger, state, animate, transition, style } from '@angular/animations';

export function fadeInAnimation() {
    return trigger('fadeInTransition', [
        transition(':enter', [
            style({ opacity: 0 }),
            animate('2s', style({ opacity: 1 }))
        ])
    ]);
}

【问题讨论】:

    标签: angular angular2-routing angular-animations


    【解决方案1】:

    这不是 DRY 但是.. 将以下内容添加到每个组件的工作中。

    import { fadeAnimation } from "./animations/fade.animation";
    
    @Component({
      selector: "app-some-other-component",      
      animations: [fadeAnimation()] 
    })
    
    @HostBinding('@fadeInTransition') fadeInTransition;
    

    【讨论】:

    • 感谢您的尝试。它是这样工作的,但就像你说的那样,这不是最好的解决方案。如果您找到应用组件解决方案,请告诉我。
    • 我找到了这个解决方案,但它也不适用于更改路线:medium.com/google-developer-experts/…
    猜你喜欢
    • 2017-09-07
    • 1970-01-01
    • 2018-04-09
    • 2018-05-07
    • 2017-12-09
    • 2019-05-22
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多