Angular анимация для router-outlet

Библиотека анимаций ngx-animations предоставляет удобное решение для Router анимаций.

Сначала стандартно добавляется свойство animation в data:

{
    path: "animals",
    component: AnimalsComponent,
    data: { animation: "AnimalsPage" }  // значение для выбора типа анимации
},
{
    path: "fruits",
    component: FruitsComponent,
    data: { animation: "FruitsPage" }
}

и прокидываются в @routeAnimation

<main [@routeAnimation]="o.activatedRouteData.animation">
    <router-outlet #o="outlet"></router-outlet>
</main>

Далее берем { animations, buildRouteTransition } from 'ngx-animations' и делаем приятно.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  animations: [
    trigger('routeAnimation', [
      buildRouteTransition({
        stateChangeExpr: "FruitsPage => AnimalsPage",
        enter: animations.zoomInLeft(500),
        leave: animations.zoomOutRight(200)
      })
      buildRouteTransition({
        stateChangeExpr: '* => *', 
        enter: animations.fadeIn(125),
        leave: animations.fadeOut(125),
      }),
    ]),
  ],
})
export class AppComponent {}

Demo

Похожие записи

Angular attribute setter

Пример задания значения булева Input свойства как директивы, на примере:

09 октября 2018 г. в Angular

Angular & MVVM

  • Model - just file like user.class.ts
  • View - HTML template of component
  • ViewModel - Typescript part of a component
14 апреля 2019 г. в Angular

Вставить <script> в Angular компонент

Добавление сторонних скриптов в Angular по запросу. Как известно, добавить скрипт через шаблон невозможно. Представлено решение как это сделать программно.

15 ноября 2019 г. в Angular

Вложенные формы Angular

Рассматриваются варианты встраивания форм, позволяющие переиспользовать набор полей вводе со своей логикой. @Input() родительской формы, @Output() дочерней формы, ViewChild(), ControlValueAccessor, ControlContainer