2017-12-15 9 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 Heroにも従っており、セッションのためだけに保持されている値を変更することができます。

編集#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

関連する問題