Reputation: 33
I want to update an object I first receive from a get request, then update, then put the object back in post. However, I am setting the data to an empty object ( {} )
var dataObject = {};
this.persistanceDataService.getData()
.subscribe(data => {
dataObject = data.contents;
dataObject.ussInput = this.input_box;
dataObject.ussData = this.data;
})
this.persistanceDataService.setData(dataObject)
.subscribe((res: any) => { });
Upvotes: 1
Views: 175
Reputation: 16441
First get the first observable, process it using map
, then apply switchMap
with the processed data to get the second observable. Finally subscribe:
this.persistanceDataService.getData().pipe(
map(data =>return{
// process your data here
}),
switchMap(processedData =>{
this.persistanceDataService.setData(processedData)
})
).subscribe(x =>{})
Upvotes: 2