我遇到了一个问题,我的代码,使用ngRx。由于该项目是巨大的,它更是一个设计问题,我很抱歉,我没有提供一个最小的和复制的例子。
AppModule
PrimaryOutletModule
SidenavComponent
HeaderComponent
ExploitationComponentsModule [lazy loaded in AppRouting]
MapComponent
MaService
ServicesModule [imported in AppModule]
HttpServicesModule
ExploitationServicesModule
ExploitationService
在这个结构中,我将这个模块添加到
AppModule
:
@NgModule({
imports: [
StoreModule.forRoot(exploitationReducers),
]
})
export class ExploitationStoreModule { }
PrimaryOutletModule
,
ExploitationComponentsModule
,和
ExploitationServicesModule
,并将其从
应用程序模块
它停止工作了。
我想从AppModule中删除它,以避免创建全局可访问的存储(我想给它们有意义的作用域)
我的第一个想法是记录
select
和
dispatch
事件,当我这么做时,我发现事件没有被捕获。将此添加到模块后:
constructor() { console.log('Store module instance created'); }
我看到两个例子。跟随
this SOF question
,我意识到我必须使用
forRoot
方法
StoreModule
.
但自从我
ExploitationStoreModule
this SOF question
,表示延迟加载的模块正在创建模块的新实例。
福鲁特
利用StoreModule
.
因为我想给我的模块提供正确的作用域,并且不让它们访问与它们没有业务往来的存储(例如,
ExploitationModule
不应访问
SupervisionStore
),我不想被迫将我的所有存储模块导入我的
.
应该如何在应用程序中声明存储,以便它们不是全局的并且只在各自的模块中提供?