我想将 component.ts 数据存储到另一个变量中,我想转换成全局变量

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

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));
}

component.ts 要存储在另一个变量中的数据

在您的 class 中声明一个数据成员并使用它,要共享数据,您可以使用 @input() 装饰器 @output 装饰器或使用服务。

    export class AppComponent {
      constructor(){}
      public data=[];//


    ngOnInit()
    { this.service.get_update(this.user).subscribe(data => this.data=data);
}