Omega
Omega

Reputation: 21

store.select(state => state) state is undefined

I'm trying to retrieve state info using the following approach:

this.store.select(state => console.log(state));

Somewhere i have mistake unfortunately I don't know where, if somebody can see him I will be grateful.

Below I am placing the code in which the mistake is, I am thanking in advance for all help.

[action]:

import { IWindowParameters } from "../window-parameters.interface";

/* NgRx */
import { Action } from '@ngrx/store';

export enum AppWeatherActionTypes {
    SetCurrentWindowParameters = "[App] Set Current Window Parameters"
}

// Action Creators
export class SetCurrentWindowParameters implements Action {
    readonly type: string = AppWeatherActionTypes.SetCurrentWindowParameters;

    constructor(public payload: IWindowParameters) { }
}

export type AppWeatherActions = SetCurrentWindowParameters

[reducer]:

/* NgRx */
import { createFeatureSelector, createSelector } from '@ngrx/store';
import * as fromAction from "../actions/app-weather.action";
import { IWeatherAppState } from "../state/app-weather.state";


export const initialAppState: IWeatherAppState = {
    windowParameters: null
};


export function appReducer(state = initialAppState, action: fromAction.AppWeatherActions): IWeatherAppState {

    switch (action.type) {

        case fromAction.AppWeatherActionTypes.SetCurrentWindowParameters:
            return { ...state, windowParameters: { ...action.payload } }

    default:
        return state;
    }
}

[state]

import { IWindowParameters } from "../window-parameters.interface";


export interface IWeatherAppState {
    windowParameters: IWindowParameters;
}

[app.module.ts]

/* NgRx */
import { StoreModule } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { environment } from '../environments/environment';
import { appReducer } from "./reducers/app-weather.reducer";

@NgModule({
  declarations: [
        AppWeather,
        WeatherMainScreen,
        WeatherView,
        WeatherPlugins,
        WeatherInfoPanel,
        MyHighlightDirective
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
      StoreModule.forRoot({ windowParameters: appReducer}),
    StoreDevtoolsModule.instrument({
        name: 'Weather Radar App DevTools',
        maxAge: 25,
        logOnly: environment.production,
    })
  ],
    providers: [
        WindowParametersService],
    bootstrap: [AppWeather]
})
export class AppModule { }

Upvotes: 1

Views: 253

Answers (1)

Sonu Kapoor
Sonu Kapoor

Reputation: 1637

The select function expects a slice from your state, which can be a string or an object. The function then returns an Observable to which you can subscribe. Something like this:

this.store.select('pizzas').subscribe(console.log);

Upvotes: 3

Related Questions