我有 2 个模块,app.module
和 lazy.module
.可以想象,lazy.module
被延迟加载到 app.module
通过路由器。
const routes: Routes = [
{ path: '', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
];
现在,在 app.module
, 我正在导入 BrowserModule
和 BrowserAnimationsModule
@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/