我在localStorage中存储了2个密钥,我想在我的模板中显示其中一个.我无法访问这些值.我甚至创建了一个接口,只是为了存储localStorage中currentUser键的值.应该如何实施呢?
这是当前的代码:
服务
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Md5 } from 'ts-md5/dist/md5';
import { User } from './user';
import 'rxjs/add/operator/map';
@Injectable()
export class VehicleService {
private defUrl = 'dummy-url.com';
constructor(private http: Http) { }
getVehicle(username?: string, password?: string) {
const url = (!username || !password) ? this.defUrl : 'dummy-url.com' + username + '/' + Md5.hashStr(password);
return this.http.get(url)
.map(res => res.json());
}
parseUser(): any {
return JSON.parse(localStorage.getItem('parseUser'));
}
getUser(): any {
return …
Run Code Online (Sandbox Code Playgroud)