我如何设置列表并在 angular 4 firebase 中推送列表
how can I set lists and also push lists in angular 4 firebase
我有一个项目列表...我想使用文本框的字段推送一些值,并在添加项目时使用默认值设置一些值
我一直用这个
addResturant(resturant: resturant) {
return this.resturants.push(resturant)
}
并且餐厅包含我想要的一些详细信息
set(resturant.branches,'') also set(resturants.items,'')
我在哪里可以将它们放在按下 btn 保存时创建的相同方法中?
这是数据库架构
更好的结构是:
在您的组件中:
constructor(private resturantService:ResturantService){}
yourPushButton(resturant){
// I presume resturant is an object
resturant['branches']='';
resturant['items']='';
this.resturantService.pushResturant(resturant)
}
并且在您的服务 ResturantService 中:
constructor(private db: AngularFireDatabase){} <--- if you use angularFire2
pushResturant(resturant){
const itemsRef = this.db.object('resturants/${resturant.name}')
itemsRef.update(resturant)
}
我有一个项目列表...我想使用文本框的字段推送一些值,并在添加项目时使用默认值设置一些值
我一直用这个
addResturant(resturant: resturant) {
return this.resturants.push(resturant)
}
并且餐厅包含我想要的一些详细信息
set(resturant.branches,'') also set(resturants.items,'')
我在哪里可以将它们放在按下 btn 保存时创建的相同方法中?
这是数据库架构
更好的结构是:
在您的组件中:
constructor(private resturantService:ResturantService){}
yourPushButton(resturant){
// I presume resturant is an object
resturant['branches']='';
resturant['items']='';
this.resturantService.pushResturant(resturant)
}
并且在您的服务 ResturantService 中:
constructor(private db: AngularFireDatabase){} <--- if you use angularFire2
pushResturant(resturant){
const itemsRef = this.db.object('resturants/${resturant.name}')
itemsRef.update(resturant)
}