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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -