angular4 使用npm上的ngx-smart-modal 出现错误?

在默认路由首页模块中可以正常使用,而懒加载后一个模块后报错,错误如下:

clipboard.png

我的两个模块中的代码一致

// 这是首页
@NgModule({
  imports: [
    AppHomeRoutes,
    CommonModule,
    FormsModule,
    NgxSmartModalModule.forRoot()
  ],
  declarations: [
    AppHomeComponent
  ],
  providers: [
  ]
})
export class AppHomeModule {}
//这是另一个模块
@NgModule({
  imports: [
    AppDiscoverRoutes,
    CommonModule,
    FormsModule,
    NgxSmartModalModule.forRoot()
  ],
  declarations: [
    AppDiscoverComponent,
    DiscoverOutletComponent,
    DiscoverDetailComponent
  ],
  providers: []
})
export class AppDiscoverModule {}
// 根模块和根路由
@NgModule({
  imports: [
    BrowserModule,
    AppRootRoutes,
    CommonModule,
    FormsModule,
    HttpModule,
    JsonpModule,
    AppHomeModule,
    NgxSmartModalModule.forRoot()
  ],
  declarations: [
    AppRootComponent
  ],
  bootstrap: [
    AppRootComponent
  ],
  providers: [
    NgxSmartModalService,
    HttpService
  ]
})
export class AppRootModule {
}
const routes: Routes = [
  {
    path: '',
    redirectTo: 'index',
    pathMatch: 'full'
  },
  {
    path: '',
    component: AppRootComponent
  },
  {
    path: 'discover',
    loadChildren: '../app-discover/app-discover.module#AppDiscoverModule'
  },
  {
    path: 'news',
    loadChildren: '../app-news/app-news.module#AppNewsModule'
  },
  {
    path: 'help',
    loadChildren: '../app-help/app-help.module#AppHelpModule'
  }
];
阅读 3.2k
2 个回答

Then add NgxSmartModalModule (with .forRoot() or .forChild() depending if the module which you import the library into is the main module of your project or a nested module) and NgxSmartModalService to your project NgModule

AppHomeModule中是不是应该导入NgxSmartModalModule.forChild(),而不是forRoot()

看看项目的 issue

因为他导入了BrowserModule,导致重复导入了。等待作者修复。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题