2017-12-15 1 views
0

다음 예제를 따르고 있습니다. https://github.com/PillowPillow/ng2-webstorage 이것은 boundValue가 저장되어 있으므로 검색 할 수 있습니다. 그러나, 나는 봇의 목록이 있습니다Angular2를 사용하는 여러 필드에 대한 LocalStorage

bot.component.html

<tr *ngFor="let bot of bots" 
     routerLink="/botlevelup/{{bot.id}}"> 
      <td>{{bot.id}}</td> 
      <td>{{bot.lastLevel}}</td> 
</tr> 

botlevelup.component.html

Last Level: {{boundValue}} 
<input [(ngModel)]="bot.lastLevel" /> 

botlevelup.component.ts을

this.storage.store('boundValue', this.bot.lastLevel); 

방법 내 모든 봇에 대한 값을 저장하기 위해 webstorage를 사용할 수 있습니까?

Edit # 1 : Tours of Heroes도 따라 갔고 세션에만 유지되는 값을 변경할 수 있습니다.

편집 # 2 : 원래 getBots 디스플레이 모든 봇 니펫 다음과 같이

getBots(): Observable<Bot[]> { 
     return this.http.get<Bot[]>(this.botsUrl) 
     .pipe(
     catchError(this.handleError('getBots', [])) 
    ); 
    } 

답변

0

당신은 직접, 그냥 해

객체/배열로서 로컬 스토리지 내부에 저장할 수 있습니다

this.storage.store('botsboundvalue', JSON.stringify(this.bots)); 
+0

더 자세히 설명해 주시겠습니까? 이 줄로 바뀌었지만 아무 일도 일어나지 않습니다. 고맙습니다! this.storage.store ('boundValue', JSON.stringify (this.bots)); – icedmilocode

+0

아무 일도 없다는 것은 무엇을 의미합니까? 로컬 저장소에있는 모든 봇의 값을 저장해야합니다. – Sajeetharan

+0

botlevelup.component.html에 반영된 로컬 저장소에 저장되어 있습니다. 그러나 값은 내 bot.component.html에 반영되지 않습니다. – icedmilocode

관련 문제