Angular 2 Animation - 如何在从路由到路由的过程中同时为两个路径组件设置动画?

时间:2016-05-23 01:57:56

标签: animation angular angular2-routing

我知道我们可以返回ngOnDestroy方法的承诺,这样我们就可以有足够的时间为淡出HTML等组件制作动画。但是,有可能淡出当前路线的HTML并淡入HTML,以便同时接下来的路线。

组件内部:

export class BaseResourceComponent extends BaseComponent implements OnDeactivate {
    ...
    routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
        return new Promise((res, rej) => setTimeout(() => res(true), 400));
    }
}

我知道如何在Angular 1中做到这一点,但确实不确定Angular 2是否支持它。

1 个答案:

答案 0 :(得分:-2)



/////////////////////////////////////////////////////////////////
// About Component Start
/////////////////////////////////////////////////////////////////
@Component({
  selector: 'about-cmp'
})

@View({
  template: `
    <h2 class="title">About Page</h2>
  `
})

class AboutCmp implements OnActivate, onDeactivate {

  onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
    console.log("About Page - initialized");
  }

  onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
    console.log("About Page - destroyed");
  }

}
&#13;
&#13;
&#13;

相关问题