如何将@ngrx/store集成到Angular 5项目中?
我正在与@ngrx/store合作Angular 5项目。 将ngrx/store集成到我的应用程序中的方法如下 我有CoreModule,其中包括store。在存储目录中,有名为search和user的目录,还有reducer.ts和index.ts如何将@ngrx/store集成到Angular 5项目中?,angular,ngrx-store-4.0,Angular,Ngrx Store 4.0,我正在与@ngrx/store合作Angular 5项目。 将ngrx/store集成到我的应用程序中的方法如下 我有CoreModule,其中包括store。在存储目录中,有名为search和user的目录,还有reducer.ts和index.ts src - app - core - store - user (index, reducer, actions, selectors) - search (index, reducer, act
src - app - core - store - user (index, reducer, actions, selectors)
- search (index, reducer, actions, selectors)
- reducers.ts
- index.ts
异径管
export interface AppState {
search: Search;
user: User;
}
export let AppReducers: ActionReducerMap<AppState> = {
search: searchReducer,
user: userReducer
};
export let AppActions = [SearchActions,UserActions];
为了将CoreStoreModule集成到根模块中,我采用了这种方式
在核心目录下的index.ts中
@NgModule({
imports: [
CoreStoreModule,
],
declarations: [
],
exports: [
CoreStoreModule,
],
providers: [
...APP_SERVICES,
]
})
export class CoreModule {
}
和根模块的app.module.ts
@NgModule({
imports: [
BrowserModule,
HttpModule,
FormsModule,
CoreModule,
RouterModule.forRoot(routes, {useHash: true})
],
declarations: [
AppComponent
],
bootstrap: [AppComponent],
providers: []
})
export class AppModule {
}
platformBrowserDynamic().bootstrapModule(AppModule);
我在编译时没有遇到任何错误,但reducer永远不会工作,在调度操作时不会发生任何事情。我正在使用的库是
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^5.1.0",
"@angular/core": "^5.2.0",
关于如何使用ngrx/store 5,没有太多文档提供信息。。有人能提供一些信息吗?如何将@ngrx/store集成到Angular 5项目中?此处提供的是字符串而不是实际变量:
StoreModule.forRoot('AppReducers')
改为:
StoreModule.forRoot(AppReducers)
或者,如果这不起作用,这可能:
StoreModule.forRoot({
search: searchReducer,
user: userReducer
})
如果您将核心模块存储注册为功能模块:
StoreModule.forFeature('core',reducers),
并在应用程序模块中注册一个空存储:
export interface State {}
export const reducers: ActionReducerMap<State> = {};
@NgModule({
declarations: [AppComponent],
imports: [
...
StoreModule.forRoot(reducers, { metaReducers }),
...
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
导出接口状态{}
导出常量缩减器:ActionReducerMap={};
@NGD模块({
声明:[AppComponent],
进口:[
...
forRoot(还原程序,{metaReducers}),
...
],
提供者:[],
引导:[AppComponent],
})
导出类AppModule{}
实际上,我想我已经试过了,但会再试一次!不幸的是,它仍然不起作用。当动作被调度时,什么也不会发生。@AnnaLee不能在没有演示的情况下进一步帮助您。
export interface State {}
export const reducers: ActionReducerMap<State> = {};
@NgModule({
declarations: [AppComponent],
imports: [
...
StoreModule.forRoot(reducers, { metaReducers }),
...
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}