2016-09-21 55 views
1

的订阅数据的值,我写的,我想在我的数据返回“显示”一个注射服务,我成功地做了如下,如何获得angular2

export class GetAllList { 
    str = localStorage.getItem('social'); 
    loc = JSON.parse(this.str); 
    id = this.loc._id; 
    private _productUrl = 'http://localhost:3000/getprofiledetails/'+this.id; 

    constructor(private _http: Http) { } 

    getList(): Observable<IDetails[]> { 
     return this._http.get(this._productUrl) 
    .map((response: Response) => {  
     return response.json().data.display; 

     }); 

    } 
} 

我在这里订阅它,

this._profileservice.getList() 
     .subscribe(
      details1 => this.details1 = details1); 
     console.log("displaystas:"+this.details) 

的问题是,我的控制台显示未定义的?所以,我怎么能看到我的显示值在我的控制台?谁能给我建议你help.Thank。

回答

1

您打印错误变量(details而不是details1)和你错过{}

this._profileservice.getList() 
    .subscribe(
     details1 => { 
     this.details1 = details1; 
     console.log("displaystas: " + this.details1) 
     } 
+1

谢谢,其wrkng NW – klp