我正在尝试使用以下方法检索状态信息:
this.store.select(state => console.log(状态));
不幸的是,我在哪里弄错了,我不知道在哪里,如果有人能看到他,我会很感激。
下面我放了错误的代码,我要提前感谢大家的帮助。
动作
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减速机
/* 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;
}
}状态
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 { }发布于 2019-07-28 11:09:55
select函数需要来自状态的切片,它可以是字符串或对象。然后该函数返回一个Observable,您可以对其执行subscribe操作。如下所示:
this.store.select('pizzas').subscribe(console.log);
https://stackoverflow.com/questions/57237413
复制相似问题