我有一个 Observable,它有一个数组。我想在 Observable 之外获取该数组,以便可以将它与另一个数组合并。
this.builderService.getCommercialData()
.subscribe(
data=>{
this.commercialDetails = data;
this.commercialDetailsArray.push(this.commercialDetails);
console.log(this.commercialDetailsArray);
this.newcommercialDetailsArray =
this.commercialDetailsArray[0];
const arrayLength = this.commercialDetailsArray.length;
if (arrayLength < 1) {
this.loaderStatus = false;
this.dataLoaded = false;
this.noData = true;
} else {
this.loaderStatus = false;
this.dataLoaded = true;
this.noData = false;
}
},
error=>{},
);
我想获取newcommercialDetailsArray
最佳答案
I have done it using Angular 2
ts 文件
ngOnInit() {
this._basicService.getBasic().subscribe(
data => {
this.basicResponse = data;
console.log(this.basicResponse);
return this.basicResponse;
}
)
}
I have get the data from service and put into basicResponse and just return the data from subscribe function console it to another onclick function to check that basicResponse if coming or not.
save()
{
console.log(this.basicResponse)
}
Just return the values.It worked for me
关于javascript - 如何在 Angular 中获取可观察对象之外的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47711066/