Angular NGRX 4商店没有使用任何

Angular NGRX 4商店没有使用任何,angular,redux,ngrx,ngrx-store,Angular,Redux,Ngrx,Ngrx Store,我正在尝试使用ngrx存储状态,但没有类似的模型 export interface AppStore{ competitions:any[]; } 但是当它返回未定义时,我现在不知道如何在任何情况下使用操作负载,我已经厌倦了搜索它,请帮助 this.store.select('competitions').subscribe(data=> console.log(data)).unsubscribe(); 我总是不确定,请帮忙 this.store.select('compet

我正在尝试使用ngrx存储状态,但没有类似的模型

export interface AppStore{
    competitions:any[];
}
但是当它返回未定义时,我现在不知道如何在任何情况下使用操作负载,我已经厌倦了搜索它,请帮助

this.store.select('competitions').subscribe(data=> console.log(data)).unsubscribe();
我总是不确定,请帮忙

this.store.select('competitions').subscribe(data=> console.log(data)).unsubscribe();
使用NGRX

在组件中创建状态

export interface AppState{
    comp:any;
}

ngOnInit(){
        this.store.dispatch({type:GET_COMP,payload: {}});
}
行动

export const GET_COMP = 'GET_COMP';
export const SUCCESS = 'SUCCESS';

export class GetAction implements Action {
  readonly type = GET_COMP;

  constructor(public payload: any) {}
}

export class SuccessAction implements Action {
  readonly type = SUCCESS;

  constructor(public payload: any) {}
}

export type Actions =
  | GetAction
  | SuccessAction
;
@Injectable()
export class MainEffects {

  constructor(private action$: Actions, private service$ :CompetitionService ) { }

  @Effect() load$:Observable<Action> = this.action$
      // Listen for the 'LOGIN' action
      .ofType(GET_COMP)
      .switchMap(action => this.service$.getComp()
        // If successful, dispatch success action with result
        .map(res => ({ type: SUCCESS, payload: res}))
        // If request fails, dispatch failed action
        .catch((err) => Observable.of({ type: 'FAILED' ,payload :err}))  
      );
}
效果

export const GET_COMP = 'GET_COMP';
export const SUCCESS = 'SUCCESS';

export class GetAction implements Action {
  readonly type = GET_COMP;

  constructor(public payload: any) {}
}

export class SuccessAction implements Action {
  readonly type = SUCCESS;

  constructor(public payload: any) {}
}

export type Actions =
  | GetAction
  | SuccessAction
;
@Injectable()
export class MainEffects {

  constructor(private action$: Actions, private service$ :CompetitionService ) { }

  @Effect() load$:Observable<Action> = this.action$
      // Listen for the 'LOGIN' action
      .ofType(GET_COMP)
      .switchMap(action => this.service$.getComp()
        // If successful, dispatch success action with result
        .map(res => ({ type: SUCCESS, payload: res}))
        // If request fails, dispatch failed action
        .catch((err) => Observable.of({ type: 'FAILED' ,payload :err}))  
      );
}
应用程序模块

StoreModule.forRoot({MainReducer}),
EffectsModule.forRoot([MainEffects])
减速器工厂

export const reducers: ActionReducerMap<AppStore> = {
     competitions: MainReducer
};
导出常量缩减器:ActionReducerMap={
比赛:主减速器
};

您是否已经阅读了@ngrx/platform中的迁移指南?是的@Jota.Toledo,我就是没法理解。我们是否需要更改此代码?我很困惑\n您是否尝试在回购或plunker中转换代码,并告诉我们您在哪里遇到了问题?您是否已经阅读了@ngrx/platform中的迁移指南?是的@Jota.Toledo我就是无法理解。我们是否需要更改此代码?我很困惑\n您是否尝试在回购或Plunk中转换此代码,并告诉我们您在哪里遇到了问题?