나는 angular2app 있습니다. 내 데이터를 localstorage에 저장했습니다. 로컬 저장소 데이터를 가져 오는 작업이 취소 될 때마다 어떻게이 localstorage 데이터를 ngrxstore에 저장할 수 있습니까?로컬 저장소 및 ngrxstore
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;
}
}
내보기는
component.ts :
- ABC
- PQR -----> 나는 다음이 이것은 목록입니다.
- 가 QWE 내가 ABC 3 가지를 클릭하고있어 동안
같은 로컬 스토리지에 저장하세요 : 내가 배열에 업데이트 얻을 것이다 CLIK 후 다음
[{name: "abc", timestamp:time, type: "typename"}].
[{name: "abc", timestamp:time, type: "typename"}, {name: "pqr", timestamp:time, type: "typename"}].
그러나 페이지를 새로 고침하고 동일한 항목을 클릭하면 이전에 저장된 데이터가 손실되고 배열이 새로운 값으로 업데이트됩니다. 하지만 실제로 필요한 것은 새로운 추가 배열입니다. 이는 이전에 저장된 데이터와 새로 저장된 데이터를 의미합니다. 어떻게 구현할 수 있습니까?
모든 evnt를 얻기 위해이 로컬 저장소 데이터를 ngrx 저장소에 저장할 수 있습니까? 나는 angular2와 ngrx 가게가 처음이다. 어떤 도움을 주셔서 감사합니다.