我正在尝试订阅一个Observable并从响应中分配一些数据,但是我的代码不等待响应。基本上,console.log(this.newIds)首先运行,并且始终为空,因为订阅不等待后端的响应。我该如何强制代码等待响应?
this.repository.getById(Ids).subscribe((response) => {
console.log(response);
this.newIds = response.map((id) => {
return id;
});
});
console.log(this.newIds);