2
votes

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

3

3 Answers

2
votes

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));
0
votes

You can log the response or you can interpolate the value of update variable in the template.

this.service.get_update(this.user).subscribe((response) => {
    this.varibleName = response;
    console.log(this.varibleName);
}, (error) => {
    console.log(error);
});

or in template

{{variableName | json}}
0
votes

Also, there's an option to use async pipe

   this.serviceData = this.service.get_update(this.user).map(res => res.json())

and in your template

{{serviceData | async}}