Angular 如何使用subscribe返回值?
如何使用subscribe返回值 我试图创建一个全局变量,但没有成功Angular 如何使用subscribe返回值?,angular,subscribe,Angular,Subscribe,如何使用subscribe返回值 我试图创建一个全局变量,但没有成功 this.postServices.getData().subscribe((res)=>{ this.data = res }) console.log(this.data) 第一部分启动异步操作,console.log部分在异步操作完成之前立即运行 您必须延迟对this.data的引用,直到您知道异步操作已完成 您可以通过将console.log放在订阅处理程序
this.postServices.getData().subscribe((res)=>{
this.data = res
})
console.log(this.data)
第一部分启动异步操作,
console.log
部分在异步操作完成之前立即运行
您必须延迟对this.data
的引用,直到您知道异步操作已完成
您可以通过将console.log
放在订阅处理程序中来实现这一点:
this.postServices.getData().subscribe((res)=>{
这个数据=res;
console.log(this.data);
})
第一部分启动异步操作,在异步操作完成之前,立即运行控制台.log
部分
您必须延迟对this.data
的引用,直到您知道异步操作已完成
您可以通过将console.log
放在订阅处理程序中来实现这一点:
this.postServices.getData().subscribe((res)=>{
这个数据=res;
console.log(this.data);
})