Search code examples
angularangular2-formsangular2-servicesangular2-directives

How to Visible data in component.ts getting from Service ( Observable pattern )


service .ts

 get_update(id:any): Observable<any[]>{
    let headers = new Headers({ 'Content-Type': 'application/json'});
    let options = new RequestOptions({ headers: headers });
    return this.http.get('http://localhost:8000/vendor/'+id,options)
                        .map(response => response.json())
                        .catch(error => Observable.throw(error.statusText));       
}
component.ts

ngOnInit()

{ this.service.get_update(this.user).subscribe(data => console.log(data));

}

I want to store data in to another variable and i want to convert into Global Variable


Solution

  • I guess you want to log the response ? you just have to

    this.service.get_update(this.user).subscribe(update => console.log(update),
                                                          error => console.log(error));