[英]ionic angular ngrx how to access a store
我正在開發一個離子角cordova應用程序。 我正在嘗試打印我的狀態,例如,狀態中的所有對象。 但是它找不到我放在里面的對象。
模型
export interface Room {
id: number;
name: string;
}
行動
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: any;
constructor(private store: Store<AppState>){
this.rooms2 = this.store.select('room');
}
console.log(this.rooms2);
但是在控制台中,我只能看到一個商店對象,在其中找不到我要查找的任何數據。
NgRx 商店是被動的。
this.rooms2 = this.store.select('room');
返回一個 Observable,這可能就是你所看到的。
請嘗試以下操作:
this.rooms2.subscribe(rooms => console.log(rooms))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.