延迟加载模块上的 Angular 8 动画错误 - 找到合成属性

标签 angular angular-animations

我有 2 个模块,app.modulelazy.module .可以想象,lazy.module被延迟加载到 app.module通过路由器。

const routes: Routes = [
  { path: '', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
];
现在,在 app.module , 我正在导入 BrowserModuleBrowserAnimationsModule
@NgModule({
  imports: [ BrowserModule, BrowserAnimationsModule ]
  // ...
})
app.module , 我有一个动画叫做 flyInOutAnimation
export const flyInOutAnimation = trigger('flyInOut', [
  state('out', style({
    transform: 'translateX(-250px)',
    display: 'none'
  })),
  state('in', style({
    transform: 'translateX(0)'
  })),
  transition('in <=> out', animate('400ms ease-in-out'))
]);
lazy.module , 我有一个 FlyoutComponent使用上面的动画。
@Component({
  // ...
  animations: [ flyInOutAnimation ]
})
以及 FlyoutComponent 的用法如下
<app-flyout [@flyInOut]="showFlyout ? 'in' : 'out'"></app-flyout>
现在,当您加载使用 app-flyout 的组件时, 你会得到以下错误
Error: Found the synthetic property @flyInOut. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.
我创建了一个 Stackblitz重现错误。

最佳答案

为了让 Angular 编译器平静下来,你应该定义 animations @Component 内的房产组件的元数据 您在哪里使用 @flyInOut动画片。
它是 PersonListComponent在你的情况下:

@Component({
  ...
  animations: [ flyInOutAnimation ] <=========== add this
})
export class PersonListComponent implements OnInit {
Forked Stackblitz

关于延迟加载模块上的 Angular 8 动画错误 - 找到合成属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58032833/

相关文章:

Angular 2 - 可以重定向路由,但使用直接链接不起作用

angular - 使用路由器的 "redirectTo"中的函数来确定重定向到哪里可以防止 aot

javascript - angular是否有任何方法来计划dom的度量和变异?

angular - 调整 Angular Material2 sidenav 大小时没有动画

html - Angular Animations 滑入不起作用,只是出现

html - 使用变量 Angular 4 制作动画

javascript - 将 angular2 应用程序从本地 NodeJS 转换为网站

angular - Electron + Angular 应用程序 + 错误 : Uncaught (in promise): Error: Cannot match any routes. URL 段:

angular - Angular2 的管道如何与数据绑定(bind)一起工作?

angular - 是否可以在组件/元素的 ':enter' 或 ':leave' 事件上添加 CSS 类,例如与 Angular 10 中的动画一起使用?