angular - AngularFire2 Database modeling. Saving data to multiple path -
i'm learning use firebase database angular. managed create auth service , save userinfo in firebase database. im writing app users can buy product , need link transaction user. current state of database:
users { 021oxk8x6rql6gafc0uhzpb4vzx2 { email: test@test.com firstname: dasdsa lastname: dsadsads } } transactions { ds766jdf6rql6gafc0uh43jhfw { product: thing price: 1000 } }
this need
transactions { ds766jdf6rql6gafc0uh43jhfw { product: thing price: 1000 buyer: 021oxk8x6rql6gafc0uhzpb4vzx2 (user key) } } transactionsperuser { 021oxk8x6rql6gafc0uhzpb4vzx2 (user key) { transaction: ds766jdf6rql6gafc0uh43jhfw (transaction key) } }
my code this:
database service:
import { injectable } '@angular/core'; import { angularfiredatabase, firebaselistobservable } 'angularfire2/database'; @injectable() export class dbfirebaseservice { transdata: firebaselistobservable<any[]>; constructor(private db: angularfiredatabase) { } postdata(info: transdata) { this.db.list('transactions').push({ product: info.product, price: info.price, }); console.log(info); } } interface transdata { product: string; price: number; }
component.ts
myform: formgroup; error = false; errormessage = ''; constructor(private fb: formbuilder, private dbfr: dbfirebaseservice) { } onsub() { this.dbfr.postdata(this.myform.value); } ngoninit(): { this.myform = this.fb.group({ firstname: [''], lastname: [''], }); }
so, have questions. first 1 how can update code save data way need to. , second 1 if proper way model data in nosql database?
thanks help! appreciate it!
Comments
Post a Comment