当我尝试在console.log(state)中显示动作结果时,我的结果是undefined,请提供任何帮助, 我在7号角工作
appReducers.ts
import {ACTION_LOGOUT, ACTION_LOGIN} from '../actions/appActions'
export interface appReducerState{
login:boolean
}
const inisalState :appReducerState= {
login : false,
}
export function reducer(state=inisalState, action):appReducerState{
switch(action.type){
case ACTION_LOGOUT:
return {
...state,
login:false
}
case ACTION_LOGIN:
return {
...state,
login:true
}
}
}
index.ts
import { reducer, appReducerState } from './appReducer'
import{ ActionReducerMap} from '@ngrx/store'
interface AppState {
appReducer:appReducerState
}
export const reducers:ActionReducerMap<AppState>={
appReducer: reducer
}
appActions.ts
export const ACTION_LOGOUT="LOGOUT"
export const ACTION_LOGIN="LOGIN"
当我尝试在此ngOnInit中显示动作结果时
mycomponent.ts
.....
constructor(
......
private store:Store<any>
.....
)
.....
ngOnInit() {
this.store.select('appReducer').subscribe(state=>{
console.log(state);
})
}
.....