最佳答案
我有一个这样的数组:
[{name:"test", time:"Date 2017-02-03T08:38:04.449Z"}]
我将它存储在 localstorage
中,当我从 localstorage
中检索数据时,我得到了这个值:
[object, object]
我怎样才能解决这个问题?
Config.ts
import { Injectable } from "@angular/core";
@Injectable()
export class TokenManager {
public tokenKey: string = 'app_token';
constructor() { }
store(content) {
var contentData;
console.log("inside localstorsge store:", content);
contentData = content.map(
(data) => data.name
)
console.log("contentData:", contentData)
localStorage.setItem(this.tokenKey, content);
}
retrieve() {
console.log("inside localstorage");
let storedToken: any = localStorage.getItem(this.tokenKey);
console.log("storedToken:", storedToken);//====> here this console is[object object]
if (!storedToken) throw 'no token found';
return storedToken;
}
}