2

无法让 Angular4 使用延迟加载和动画。所以我加载BrowserAnimationsModule了我的 app-modules.ts 并且动画在主模块中工作正常,但在延迟加载的模块中没有,所以我尝试 BrowserAnimationsModule在我的共享模块中加载,因为我收到以下错误: Unhandled Promise rejection: BrowserModule has already been loaded. If you need access to common directives

这是我的共享模块:

var sharedComponents = [Tabs, Tab, Infobox, Sliderpanel, Slideritem, SlideritemContent, PanelSplitMain, PanelSplitSide, PanelSplitContainer, ListToArrayPipe, FormatSecondsPipe, MatchBodyHeight, ScreenTemplate, BlurForwarder, DraggableList, AddContent, Loading,
    FontSelector, BlockPropContainer, BlockPropCommon, BlockPropHtml, BlockPropClock, BlockPropWeather, BlockPropInstagram, BlockPropJsonPlayer, BlockPropJsonItem, LivePreview, LocationMap, MediaPlayer, FilterModelPipe, SvgIcon,
    BlockPropScene, BlockPropCalendar, BlockPropSheets, BlockPropTwitter, BlockPropVideo, BlockPropImage, BlockPropLabel, BlockPropMrss, BlockPropLocation, BlockPropRss, BlockPropDigg, BlockPropFasterQ, BlockPropCollection, BlockPropQR, BlockPropYouTube, JsonEventGrid];

@NgModule({
    imports: [CommonModule, FormsModule, HttpModule, JsonpModule, ReactiveFormsModule, ContextMenuModule, ChartModule, ReactiveFormsModule, ColorPickerModule, DropdownModule, RadioButtonModule, SimpleGridModule, Ng2Bs3ModalModule, AgmCoreModule, VgCoreModule, VgControlsModule, VgOverlayPlayModule, VgBufferingModule],
    exports: [CommonModule, FormsModule, HttpModule, JsonpModule, ReactiveFormsModule, ContextMenuModule, ChartModule, ColorPickerModule, DropdownModule, RadioButtonModule, SimpleGridModule, Ng2Bs3ModalModule, AgmCoreModule, VgCoreModule, VgControlsModule, VgOverlayPlayModule, VgBufferingModule, ...sharedComponents],
    entryComponents: [ScreenTemplate],
    declarations: [...sharedComponents]
})

export class SharedModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: SharedModule,
            providers: []
        };
    }
}

一旦我添加它,BrowserAnimationsModule它就会出错,

想法?

谢谢,

肖恩

4

1 回答 1

2

看来您只能导入 BrowserModule 或 BrowserAnimationsModule 并且它必须位于根应用程序模块中,如此 github 问题中所述: https ://github.com/angular/angular/issues/15579

解决方案是仅在 app.module 上导入 BrowserAnimationsModule

如果有人偶然发现相同的问题,请在此处发布

于 2018-06-06T16:15:27.217 回答