Javascript 在Firebase上获取错误-FirebaseError:无效段(用户//购物车)。路径中不能包含/
在cart.component.ts中编码Javascript 在Firebase上获取错误-FirebaseError:无效段(用户//购物车)。路径中不能包含/,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,在cart.component.ts中编码 this.cart.getCart().subscribe(cs => { this.shoppingCart = cs.map( x =>{ return{ id: x.payload.doc.id, ...x.payload.doc.data() as {} } }) } getCart(){
this.cart.getCart().subscribe(cs =>
{
this.shoppingCart = cs.map( x =>{
return{
id: x.payload.doc.id,
...x.payload.doc.data() as {}
}
})
}
getCart(){
return this.fs.collection(`users/${this.as.userId}/cart`).snapshotChanges()
}
购物车.service.ts中的代码
this.cart.getCart().subscribe(cs =>
{
this.shoppingCart = cs.map( x =>{
return{
id: x.payload.doc.id,
...x.payload.doc.data() as {}
}
})
}
getCart(){
return this.fs.collection(`users/${this.as.userId}/cart`).snapshotChanges()
}
我在这里看到的唯一可能性是
this.as.userId
为空。确保该值不为空,这将解决问题。因为它是空的,getCart()
函数试图查询集合用户//购物车
,但是用户/
和/cart
部分之间应该有一个用户id