我想更新一个对象,我首先从一个get请求接收,然后更新,然后把对象放回post。但是,我正在将数据设置为空对象({})
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) => { });
最佳答案
首先得到第一个观测值,使用map
对其进行处理,然后对处理后的数据应用switchMap
得到第二个观测值。最后订阅:
this.persistanceDataService.getData().pipe(
map(data =>return{
// process your data here
}),
switchMap(processedData =>{
this.persistanceDataService.setData(processedData)
})
).subscribe(x =>{})