我正在关注这个例子:https : //github.com/PillowPillow/ng2-webstorage这对我来说很好用,因为 boundValue 被存储并且我可以检索它。但是,我有一个机器人列表:
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 为我的所有机器人存储值?
编辑 #1:我也关注了《英雄之旅》,我可以更改仅保留在会话中的值。
编辑 #2:显示所有机器人的原始 getBots 片段:
getBots(): Observable<Bot[]> {
return this.http.get<Bot[]>(this.botsUrl)
.pipe(
catchError(this.handleError('getBots', []))
);
}
您可以直接将其作为对象/数组存储在本地存储中
只需按照以下方式进行,
this.storage.store('botsboundvalue', JSON.stringify(this.bots));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句