如何从内心状态中选择

时间:2018-05-31 11:22:37

标签: angular5 ngrx

我想选择州'homepage_banner'的内部部分而且我得到了:

  TypeError: Cannot read property 'homepage_banner' of undefined
    at MapSubscriber.generalData [as project] (generalReducer.ts:37)
    at MapSubscriber._next (map.js:69)
    at MapSubscriber.next (Subscriber.js:83)
    at MapSubscriber._next (map.js:75)
    at MapSubscriber.next (Subscriber.js:83)
    at ReplaySubject._subscribe (ReplaySubject.js:46)
    at ReplaySubject._trySubscribe (Observable.js:171)
    at ReplaySubject._trySubscribe (Subject.js:87)
    at ReplaySubject.subscribe (Observable.js:159)
    at Observable._subscribe (Observable.js:229)

当我从状态中选择模块时,只有当我尝试进入内层时才会出现问题
这是我的州:

enter image description here

这是模块界面:

  export interface IAppGeneral {
     modules:{
        [key:string]: { 
            html:{
                data: {
                    [key:string]:string;
                }
            }
            css:{
                data: {
                    [key:string]:string;
                }
            }
        }

    }


}

这是减速器:

  import {createSelector,createFeatureSelector} from '@ngrx/store';
import * as generalActions from './../actions/general.actions';

import {  IAppGeneral } from '../model/generalModel';


export interface IAppState {
    appGeneralData:  IAppGeneral ;
}

const initialState: IAppState = {
    appGeneralData:[]
};


export function appGeneralReducer(state = initialState, action:generalActions.Actions): IAppState {

    switch (action.type) {
          case generalActions.GET_GENERAL_APP_DATA_SUCCESS:{
                         // console.log('reducerGeneral',action.payload)
                          return Object.assign( {}, state, action.payload )

                //  return {...state,appGeneralData:action.payload}     
         }

        default:  {
            return state;

        }

   }

}


 export const  generalData = (state: IAppState) => state.appGeneralData['modules']['homepage_banner']

0 个答案:

没有答案