如何获取存储在本地存储中的对象

时间:2016-07-28 13:34:37

标签: typescript angular typescript1.8

我希望从存储在本地存储中的对象获取profile_id,但它显示错误

Error: Uncaught (in promise): Template parse errors:
Unexpected character "EOF" ("
</div>
</div>[ERROR ->]"): a@24:6

我的组件:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Id } from './id';

@Injectable()
export class GetId {
    str = localStorage.getItem('social_id');
    loc = JSON.parse(this.str);
    id = this.loc.profile_id;

    private _productUrl = 'http://localhost/a2server/index.php/requests/getrequestnotification/' + this.id;

    constructor(private _http: Http) { }

    getId(): Observable<Id[]> {
        return this._http.get(this._productUrl).map((response: Response) => {
            console.log(response);
            return <Id[]> response.json();
        });
    }
}

有人可以建议帮助..........

0 个答案:

没有答案