내가이 라이브러리 다음하고 사용하여 새로 고침 후 작동하지 않습니다 로컬 저장소에 저장하고 webstorage를 사용하여 검색하십시오. 메모리 - data.service로컬 저장소는 Angular2 인 - 메모리 데이터
<tr *ngFor="let bot of bots" routerLink="/botlevelup/{{bot.id}}">
<td>{{bot.id}}</td>
<td>{{bot.lastLevel}}</td>
<td>{{bot.secondLevel}}</td>
</tr>
그러나, 새로 고침 후, 내 값은 인 - 메모리 data.service.ts
bot.component.html에 저장된 이전 내용으로 되돌립니다. TS :
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const bots = [
{"id":1,"lastLevel":5},
{"id":2,"lastLevel":5},
{"id":3,"lastLevel":5}
];
return {bots};
}
}
botlevelup.component.html
Bot: {{bot.id}}
Last Level: <input [(ngModel)]="bot.lastLevel" />
<button (click)="save()">Save</button>
botlevelup.component.ts
save() {
this.storage.store('boundValue', JSON.stringify(bot));
}
업데이트 된 값은 콘솔 로그를 사용하여 'boundValue'에 저장되며 새로 고침 후에도 계속 유지됩니다.
새로 고침 후 원래의 in-memory-data.service.ts 대신 'boundValue'에서 업데이트 된 값을 어떻게 검색합니까?
나는 달성 싶었 다른 경우 : 봇 1과 2에 대한 변경 사항이있는 경우, 그것은 'boundValue'에서 검색합니다- 봇 3에 만들어진 변경 사항이 없을 경우 , 그것은 in-memory-data.service에서 검색합니다.
편집 # 1 : 나는 업데이트가없는 경우 봇의 업데이트 된 값, 또한 로봇의 이전 값을 기준으로 테이블을 다시 반환하는 관리 검색
getBots(): Observable<Bot[]> {
this.storage.retrieve('boundValue');
return this.http.get<Bot[]>(this.botsUrl)
.pipe(
catchError(this.handleError('getBots', []))
);
}
IIFC, 각'bot' 객체에 대한 키로'boundValue'를 사용하고 있습니까? 이 경우 최종 업데이트는'boundValue'와 연관된 이전 값을 덮어 쓴 b/c 만 볼 수 있습니다. – bazzells
두 봇을 모두 boundValue에 이미 저장할 수있었습니다. 새로 고침 후 봇을 표시하는 방법은? – icedmilocode
어떻게 스토리지에서 데이터를 가져 왔습니까? docs 패키지에서 retrieve 메소드를 사용 했습니까? – bazzells