angular - AOT 的 Angular 8 BrowserAnimations 错误
问题描述
我有route-animations.ts
一些动画。当我使用它运行代码时,ng serve
它工作正常,但使用ng serve --prod
.
export const slider =
trigger('routeAnimations', [
transition('* => isLeft', slideTo('left') ),
transition('* => isRight', slideTo('right') ),
transition('isRight => *', slideTo('left') ),
transition('isLeft => *', slideTo('right') )
]);
function slideTo(direction) {
const optional = { optional: true };
return [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
[direction]: 0,
width: '100%'
})
], optional),
query(':enter', [
style({ [direction]: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ [direction]: '100%'}))
], optional),
query(':enter', [
animate('600ms ease', style({ [direction]: '0%'}))
])
]),
];
}
我得到这个错误ERROR in src\app\app.component.ts(14,16): Error during template compile of 'AppComponent'
Reference to a non-exported function in 'slider'
'slider' contains the error at src\app\animations\route-animations.ts(41,10).
import { Component } from '@angular/core';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { RouterOutlet } from '@angular/router';
import { slider } from './animations/route-animations';;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
animations: [slider]
})
export class AppComponent {
constructor() { }
prepareRoute(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
}
}
解决方案
解决方案非常简单,我们只需要将导出的 const 和函数合并为一个 const。
export const slider =
trigger('routeAnimations', [
transition('* => isLeft', [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
left: 0,
width: '100%'
})
], { optional: true }),
query(':enter', [
style({ left: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ left: '100%'}))
], { optional: true }),
query(':enter', [
animate('600ms ease', style({ left: '0%'}))
])
]),
]),
transition('* => isRight', [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
right: 0,
width: '100%'
})
], { optional: true }),
query(':enter', [
style({ right: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ right: '100%'}))
], { optional: true }),
query(':enter', [
animate('600ms ease', style({ right: '0%'}))
])
]),
]),
transition('isRight => *', [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
right: 0,
width: '100%'
})
], { optional: true }),
query(':enter', [
style({ left: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ left: '100%'}))
], { optional: true }),
query(':enter', [
animate('600ms ease', style({ left: '0%'}))
])
]),
]),
transition('isLeft => *', [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
right: 0,
width: '100%'
})
], { optional: true }),
query(':enter', [
style({ right: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ right: '100%'}))
], { optional: true }),
query(':enter', [
animate('600ms ease', style({ right: '0%'}))
])
]),
])
],
)```
推荐阅读
- reactjs - 未处理的拒绝(TypeError):无法读取未定义的属性“项目”
- c++ - C ++如何在同一行中进行cin和cout?
- reactjs - 在 react-leaflet 中定位标记方向,面向 [long, lat]
- symfony - 设置本地端口以使用 Symfony HttpClient 发出请求
- html - 缩小联系表格
- python - 在调用 deleteLater() 后直接删除对 Qt 对象的 Python 引用是否安全?
- vue.js - 在 Nuxt 中使用来自布局的异步获取
- spring - 将数据从 Soring 启动应用程序添加到 Mondo DB
- docker - 如何缩小 Docker 磁盘映像,但在 Docker for Mac 中保留卷?
- direct3d - 如何处理 Direct3D 9Ex D3DERR_DEVICEHUNG 错误?