我们如何将共享的 Store、Actions、Reducers 和 Services 导出到不同的模块? - Angular
How can we export shared Store, Actions, Reducers and Services to a different module? - Angular
Store、Actions、Reducers 和一些服务位于单独的共享模块中 - 假设该模块是 shared.module.ts。如果我们想使用来自不同模块的所有这些实体,我们如何导出它?我知道我们可以将组件导出到其他模块,但是这些呢?如果我从不同的模块触发一个动作,它会触发共享模块中的减速器吗?具体到 Angular.
您的共享模块:
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { EffectsModule } from '@ngrx/effects';
import { RouterState, StoreRouterConnectingModule } from '@ngrx/router-store';
import { StoreModule } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { environment } from 'src/environments/environment';
import { reducers, metaReducers } from './app.state';
@NgModule({
declarations: [],
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
RouterModule.forRoot([]),
StoreRouterConnectingModule.forRoot({ routerState: RouterState.Minimal}),
// Instrumentation must be imported after importing StoreModule (config is optional)
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production, // Restrict extension to log-only mode
autoPause: true, // Pauses recording actions and state changes when the extension window is not open
}),
EffectsModule.forRoot([
// your effects here
]),
],
exports: [
],
providers: [],
bootstrap: [],
entryComponents: [],
})
export class SharedModule {}
然后在另一个模块中导入:
import { NgModule } from '@angular/core';
import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [],
imports: [SharedModule],
exports: [],
bootstrap: [],
})
export class CustomersModule {}
Store、Actions、Reducers 和一些服务位于单独的共享模块中 - 假设该模块是 shared.module.ts。如果我们想使用来自不同模块的所有这些实体,我们如何导出它?我知道我们可以将组件导出到其他模块,但是这些呢?如果我从不同的模块触发一个动作,它会触发共享模块中的减速器吗?具体到 Angular.
您的共享模块:
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { EffectsModule } from '@ngrx/effects';
import { RouterState, StoreRouterConnectingModule } from '@ngrx/router-store';
import { StoreModule } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { environment } from 'src/environments/environment';
import { reducers, metaReducers } from './app.state';
@NgModule({
declarations: [],
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
RouterModule.forRoot([]),
StoreRouterConnectingModule.forRoot({ routerState: RouterState.Minimal}),
// Instrumentation must be imported after importing StoreModule (config is optional)
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production, // Restrict extension to log-only mode
autoPause: true, // Pauses recording actions and state changes when the extension window is not open
}),
EffectsModule.forRoot([
// your effects here
]),
],
exports: [
],
providers: [],
bootstrap: [],
entryComponents: [],
})
export class SharedModule {}
然后在另一个模块中导入:
import { NgModule } from '@angular/core';
import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [],
imports: [SharedModule],
exports: [],
bootstrap: [],
})
export class CustomersModule {}