加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 6 / NGRX组合减速器

发布时间:2020-12-17 17:37:12 所属栏目:安全 来源:网络整理
导读:我正在使用Angular 6 w / NgRX 4.我有多个我想要结合的减速器. app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { StoreModule } from '@ngrx/store'; import { EffectsModule
我正在使用Angular 6 w / NgRX 4.我有多个我想要结合的减速器.

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';

    import { StoreModule } from '@ngrx/store';
    import { EffectsModule } from '@ngrx/effects';

    import { StoreDevtoolsModule } from '@ngrx/store-devtools';

    import { AppComponent } from './app.component';
    import counterEffects from './store/counter/counter.effects';

    import reducers from './store/reducers';

    @NgModule({
      declarations: [AppComponent],imports: [
        BrowserModule,StoreModule.forRoot(reducers),EffectsModule.forRoot([counterEffects]),StoreDevtoolsModule.instrument({
          maxAge: 10,}),],providers: [],bootstrap: [AppComponent],})
    export class AppModule {}

reducers.ts

import { combineReducers } from '@ngrx/store';
import { reducer as counterReducer,key as counterKey } from './counter';
import { reducer as profileReducer,key as profileKey } from './profile';

const appReducer = combineReducers({
  [counterKey]: counterReducer,[profileKey]: profileReducer,});

export default (state,action) => {
  if (action.type === 'REDIRECT_TO_EXTERNAL') {
    state = undefined;
  }

  return appReducer(state,action);
};

我的减速机是标准的减速机,没什么特别的.

来自React / Redux背景,我会像这样设置多个reducers,但是在Angular中,当我尝试从商店中选择时,我得到了未定义.当我尝试使用开发工具查看商店时,我看不到我的减速器和状态都不是{}

如何在Angular 6 / NgRX 4中设置多个减速器?

解决方法

import { ActionReducerMap } from '@ngrx/store';
import { reducer as counterReducer,key as profileKey } from './profile';

export interface IAppState {
  [counterKey]: any;
  [profileKey]: any;
}

export const reducers: ActionReducerMap<IAppState> = {
  [counterKey]: counterReducer,};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读