Angular 如何进入商店
我正在开发一款爱奥尼亚角科尔多瓦应用程序。我正在尝试打印我的状态,例如,状态中的所有对象。但是它找不到我放进去的东西 模型 行动Angular 如何进入商店,angular,ionic-framework,ngrx,Angular,Ionic Framework,Ngrx,我正在开发一款爱奥尼亚角科尔多瓦应用程序。我正在尝试打印我的状态,例如,状态中的所有对象。但是它找不到我放进去的东西 模型 行动 export class AddRoom implements Action { readonly type = ADD_ROOM; constructor(public payload: Room){} } 减速器 const initialState: Room = { id: 111, name: 'null' } expo
export class AddRoom implements Action {
readonly type = ADD_ROOM;
constructor(public payload: Room){}
}
减速器
const initialState: Room = {
id: 111,
name: 'null'
}
export function reducer(state: Room[] = [initialState], action: RoomActions.Actions ){
switch (action.type) {
case RoomActions.ADD_ROOM:
return [...state];
case RoomActions.REMOVE_ROOM:
state.splice(action.payload, 1);
return state;
default:
return state;
}
}
代码
rooms2:任何;
构造函数(私有存储:存储){
this.rooms2=this.store.select('room');
}
console.log(this.rooms2);
但在控制台中,我只能看到一个store对象,在该对象中我找不到任何数据。NgRx存储是被动的
this.rooms2=this.store.select('room')代码>返回一个可观察的,这可能就是您看到的
请尝试以下操作:
this.rooms2.subscribe(rooms => console.log(rooms))
rooms2: any;
constructor(private store: Store<AppState>){
this.rooms2 = this.store.select('room');
}
console.log(this.rooms2);
this.rooms2.subscribe(rooms => console.log(rooms))