0
我有一個angular2app。我將數據存儲到本地存儲中。每次獲取chage本地存儲數據的操作都將清除。我如何將這個本地存儲數據存儲到ngrxstore中。我有以下幾點:本地存儲和ngrxstore
component.ts
onClickRoom(room: string): void {
this.date = new Date();
this.evntList = new events('', '', '');
this.evntList.timestamp = this.date;
this.evntList.name = room;
this.evntList.type = this.type;
console.log("eventList:", this.evntList);
this.eventArray.push(this.evntList);
this.tokenmanager.store(this.eventArray);
console.log('Room clicked: ', this.eventArray); ---> This event array successfully updating.
}
globalstorage.ts
@Injectable()
export class TokenManager {
public tokenKey: string = 'app_token';
constructor() { }
store(content) {
localStorage.setItem(this.tokenKey, JSON.stringify(content));
}
retrieve() {
let storedToken: any = localStorage.getItem(this.tokenKey);
if (!storedToken) throw 'no token found';
return storedToken;
}
}
我的看法是:
- ABC
- PQR ----->這是一個列表。
- QWE
當我點擊ABC 3件事情被存儲到像本地存儲:
[{name: "abc", timestamp:time, type: "typename"}].
後來我一短聲陣列將得到更新到
[{name: "abc", timestamp:time, type: "typename"}, {name: "pqr", timestamp:time, type: "typename"}].
但在刷新頁面並單擊相同的項目之後,先前存儲的數據將丟失,數組將用新值更新。但實際上我需要的是一個新的附加數組。這意味着之前存儲的數據和新存儲的數據。我怎樣才能實現這個?
如何將本地存儲數據存儲到ngrx存儲區以獲取所有證據。我是angular2和ngrx商店的新手。任何幫助高度讚賞。