1

I've a list of items ... and I want to push some values with fields from textboxes and set some values with default Values on adding an Item

I always use this

addResturant(resturant: resturant) {
  return this.resturants.push(resturant)
}

and the restaurant contains some details I want to

set(resturant.branches,'') also set(resturants.items,'') 

where can I put them in the same method to be created on pressing on the btn save ?

here is the database architecture enter image description here

4
  • How is your data in firebase? can you show us some content to see the structure? I don't undertand precisly your problem. Can you do an example or add some code please Commented Oct 9, 2017 at 20:42
  • Well I want to make empty nodes called items and branches ... so it's the only way I knew to make an empty Node called items and called branches ... so I want on adding new restaurant .. items and branches nodes created with free values ... and the other restaurant keys and values push in the database normally like restaurantname , resturantdesc and so on. @Wandrille Commented Oct 9, 2017 at 20:45
  • and in your firebase database, for restaurant , is it a list with generated key? Commented Oct 9, 2017 at 20:47
  • yes it is fine to create a new restaurant with a generated key Commented Oct 9, 2017 at 20:52

1 Answer 1

1

A better structure will be:

in your component:

constructor(private resturantService:ResturantService){}

yourPushButton(resturant){
   // I presume resturant is an object
   resturant['branches']='';
   resturant['items']='';
   this.resturantService.pushResturant(resturant)
}

And in your service ResturantService:

constructor(private db: AngularFireDatabase){} <--- if you use angularFire2

pushResturant(resturant){
   const itemsRef = this.db.object('resturants/${resturant.name}')
   itemsRef.update(resturant)
}
Sign up to request clarification or add additional context in comments.

8 Comments

oh it is not an object it's a list !
When you add a new resturant, this will be an object, not a list. You have a list of resturants. You want to add more than one resturant at a time?
ok great can u tell me how to get an Object ? I always use this to get a list.
this.resturants = this.af.list('/restaurants') as FirebaseListObservable<resturant[]>;
So now I understand. The key is your resturant name. See my Edit (don't use the type for the list but the on for the object)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.