Cannot read property 'showContent' of undefined when using the ngrx in angular

488 Views Asked by At

i want to use the ngrx in my project but when i use that it show me this error :

Cannot read property 'showContent' of undefined

this is my ngrx config :

this is my reducer :

export interface State extends fromRoot.State {
    helpDesk: HelpDeskState;
}

export interface HelpDeskState {
    showContent: string;
}

const initialHelpContent: HelpDeskState = {
    showContent: 'null'
}

const getHelpContentFeatureState = createFeatureSelector<HelpDeskState>('helpDesk');
export const showHelpContnt = createSelector(getHelpContentFeatureState, state => state.showContent)


export function reducer(state = initialHelpContent, action): HelpDeskState {

    switch (action.type) {

        case 'CACH_HELP_DESK_CONTENT':
            return {
                ...state,
                showContent: action.payload
            };


        default: state;
    }
}

and i creatd the state interface for lazy loading :

export interface State {
}

now when i want to use this reducer by this code :

   constructor(private helpService: HelpService,
    private store: Store<fromHelp.State>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData) { }

  ngOnInit(): void {
    this.FetchDate()
  }

  FetchDate(): void {
    this.store.pipe(select(fromHelp.showHelpContnt)).subscribe(data => {
      if (data) {
        this.content = data
      } else {
        this.helpService.GetGelpServiceInfo(this.data.helpDeskType).subscribe(data => {
          this.content = data.result['content'];
          this.store.dispatch({
            type: 'CACH_HELP_DESK_CONTENT',
            payload: this.content
          })
        })
      }
    })
  }

show me that error .

whats the problem ? how can i solve this problem ???

0

There are 0 best solutions below