typescript - 为什么实时数据库不更新?
问题描述
addDevice(deviceId: string, fireId: string){
let Token: string;
let UserId: string;
let newDevice: Device;
return this.authSrv.userId.pipe(take(1),
switchMap(
userId => {
UserId = userId;
return this.authSrv.token;
}
),take(1),
switchMap(
token => {
if(!UserId){
throw new Error('No user id found');
}
Token = token;
return this.http.get<DeviceData>(`https://....firebaseio.com/device/${fireId}.json?
auth=${token}`)
}
),
switchMap(
deviceData => {
if(!deviceData){
throw new Error('No Device Id found or Pass Id incorrect');
}
newDevice = new Device(
fireId,
deviceData.deviceId,
deviceData.ver,
deviceData.slot,
UserId
);
this.http.put(`https://....firebaseio.com/device/${fireId}.json?auth=${Token}`,
{...newDevice, id:null}
);
return this.devices;
}
)
);
}
“get()”得到了我的数据,但“put()”没有对我的 Firebase 做任何事情,它也没有显示任何错误我尝试使用“console.log”查看数据输入。
我遵循此代码作为我的基础
places => {
const upPlaceIndex = places.findIndex(pl => pl.id == placeId);
upPlace = [...places];
const oldPlace = upPlace[upPlaceIndex];
upPlace[upPlaceIndex] = new Place(.....);
return this.http.put(`https://....firebaseio.com/offers-places/${placeId}.json?
auth=${fetchToken}`,
{...upPlace[upPlaceIndex], id: null}
}
这段代码在我的其他项目中有效
解决方案
没关系我得到它即使我不明白为什么
switchMap(
deviceData => {
if(!deviceData){
throw new Error('No Device Id found or Pass Id incorrect');
}
newDevice = new Device(
fireId,
deviceData.deviceId,
deviceData.ver,
deviceData.slot,
UserId
);
this.http.put(`https://....firebaseio.com/device/${fireId}.json?auth=${Token}`,
{...newDevice, id:null}
);
return this.devices;
}
)
我只是把它改成这个
switchMap(
deviceData => {
if(!deviceData){
throw new Error('No Device Id found or Pass Id incorrect');
}
newDevice = new Device(
fireId,
deviceData.deviceId,
deviceData.ver,
deviceData.slot,
UserId
);
return this.http.put(`https://....firebaseio.com/device/${fireId}.json?auth=${Token}`,
{...newDevice, id:null}
);
}
),
switchMap(
data => {
return this.devices;
}
)
推荐阅读
- python - SciKit Gradient Boosting - 如何将预测与初始表相结合?
- c++11 - 指向静态变量的指针必须尊重规范形式?
- javascript - 是否有支持 css 3d 的 PhantomJs 替代方案
- apache-spark - spark.table 因 java.io.Exception 失败:Scheme 没有文件系统:abfs
- matlab - 如何制作一个给出几何分布概率的函数?
- rxjs - 在 BehaviorSubject 管道中使用 shareReplay(1) 的任何理由?
- python - 在python中自动计算旋转周期
- c# - 在 Castle Windsor 中使用元数据注册组件
- node.js - 点击事件触发时什么都不做
- python - 即使元素在集合中,删除集合中的元素时也会出现 KeyError?