如何使用angularfire2在对象表中推送新的子对象
我在学习如何使用firebase 我创建了存储在firebase中的产品,作为如何使用angularfire2在对象表中推送新的子对象,angular,typescript,firebase,google-cloud-firestore,Angular,Typescript,Firebase,Google Cloud Firestore,我在学习如何使用firebase 我创建了存储在firebase中的产品,作为 product:{ name:"test1", votes: [ vote:{adressIp:"102.169.235.190", nbvote:4} ] } 这是我的目标 export interface vote{ vote:{ adresseIp:string; nbvote:number; } } 我有一个功能新贵 up
product:{
name:"test1",
votes:
[
vote:{adressIp:"102.169.235.190",
nbvote:4}
]
}
这是我的目标
export interface vote{
vote:{
adresseIp:string;
nbvote:number;
}
}
我有一个功能新贵
upstar(nbvote){
let userid:string;
this.MyuserService.getIpAddress().subscribe(
ip=>{userid=ip.ip
const up:vote ={vote:{adresseIp:userid,
nbvote:nbvote
}}
this.itemDoc.update( { votes:[up]})
}
)
当用户单击按钮时,我调用upstart
upstart的作用是将新的子对象推送到对象表中
火库
但我的问题是什么时候给upstart打电话,upstart会更新
投票[0]。投票.adressIp和投票[0]。投票.nbvote
而是将新的子对象推送到对象表中
我的目标是在调用upvote时将新的子对象推到对象表中
product:{
name:"test1",
votes:
[
vote:{adressIp:"102.169.235.190",
nbvote:4}
],
[
vote:{adressIp:"101.129.233.140",
nbvote:3}
],
}
您不能有相同的名称,这就是它覆盖的原因。您可能应该增加它,例如
vote:{..}
vote1:{..}