0

I get errors when I want to build my angular app with 'ng build --prod':

ERROR in src/app/route-animations.ts(15,9): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(20,15): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(24,39): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(27,39): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(15,9): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(20,15): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(24,39): Error during template compile of 'slideTo' Expression form not supported. src/app/route-animations.ts(27,39): Error during template compile of 'slideTo' Expression form not supported.

I don´t really know how to fix this.

I haved added router animations to my app like following:

<div [@routeAnimations]="prepareRoute(outlet)" style="height: 100%">
  <router-outlet #outlet="outlet"></router-outlet>
</div>
import { slider } from './route-animations';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  animations: [ 
    slider
  ]
})
export class AppComponent implements OnInit {
  ngOnInit(): void {
    ...
  }

  prepareRoute(outlet: RouterOutlet) {
    return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
  }
}
import { trigger, transition, query, style, animate, group } from '@angular/animations';

export const slider =
  trigger('routeAnimations', [
    transition('isRight => isLeft', slideTo('left') ),
    transition('isLeft => isRight', slideTo('right') )
  ]);

export function slideTo(direction: string) {
  return [
    query(':enter, :leave', [
      style({
        position: 'absolute',
        top: 0,
        [direction]: 0,
        width: '100%'
      })
    ], { optional: true }),
    query(':enter', [
      style({ [direction]: '-100%'})
    ]),
    group([
      query(':leave', [
        animate('600ms ease', style({ [direction]: '100%'}))
      ], { optional: true }),
      query(':enter', [
        animate('600ms ease', style({ [direction]: '0%'}))
      ])
    ]),
  ];
}
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
JuNe
  • 1,911
  • 9
  • 28

1 Answers1

1

What you want is not entirely possible as animations is not a function more of a decorator pattern syntax, but there might be a way to reuse certain animations, but very limited article on this.

Create a reusable animation with interpolation variables which can be passed from each transition option

import { trigger, transition, query, style, animate, group, animation, useAnimation } from '@angular/animations';

// Reusable animation
export const slideAnimation = animation([
  query(':enter, :leave', [
    style({
      position: 'absolute',
      top: 0,
      left: '{{left}}',
      width: '100%'
    })
  ], { optional: true }),
  query(':enter', [
    style({ left: '-{{left}}' })
  ]),
  group([
    query(':leave', [
      animate('600ms ease', style({ left: '{{left}}' }))
    ], { optional: true }),
    query(':enter', [
      animate('600ms ease', style({ left: '{{left}}' }))
    ])
  ]),
]);


export const slider = trigger('routeAnimations', [
  transition('isRight => isLeft', [useAnimation(slideAnimation, { params: { left: '0%', time: '2s' } })]),
  transition('isLeft => isRight', [useAnimation(slideAnimation, { params: { direction: '100%', time: '2s' } })])
]);

The posted solution is not exactly what you currently have and this is pointing to a right direction, I hope you can make it work

Reference: https://angular.io/guide/reusable-animations

joyBlanks
  • 6,419
  • 1
  • 22
  • 47
  • thx for your answer but isn't working for me: ERROR in src/app/route-animations.ts(3,17): Error during template compile of 'ɵ0' Function expressions are not supported in decorators Consider changing the function expression into an exported function. src/app/route-animations.ts(3,17): Error during template compile of 'ɵ0' Function expressions are not supported in decorators Consider changing the function expression into an exported function. – JuNe Sep 09 '19 at 06:22
  • another error appears: ERROR in src/app/route-animations.ts(3,10): Error during template compile of 'slider' Reference to a non-exported function. src/app/route-animations.ts(3,10): Error during template compile of 'slider' Reference to a non-exported function. – JuNe Sep 09 '19 at 06:43
  • give me a moment let me check – joyBlanks Sep 09 '19 at 06:45
  • Check this snippet, I think we cant use standard functions in animations which goes to NgModule decorator declarations but check it this helps you – joyBlanks Sep 09 '19 at 08:35