小编Has*_*eoh的帖子

Angular2如何在HTML5模板中显示localStorage值?

我在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)

html5 local-storage angular2-forms angular

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular2-forms ×1

html5 ×1

local-storage ×1