【发布时间】:2020-09-20 16:10:44
【问题描述】:
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}
}
这段代码在我的其他项目中可以使用
【问题讨论】:
标签: typescript firebase ionic-framework firebase-realtime-database