2

getting values from firebase through subscription is the option we generally follow, but suppose i have some constant value saved in firebase database, and i want to read that value on invoke of my function how can i get the value without subscription.

Problem Points I am generating a Purchase number on submit of purchase order, i am getting the last value saved in firebase and increment of +1 to that number to generate new ordernumber. i am using this through service in which i am making a call like this:

getOrderNumber() {
  this.db.list('lastOrderNumber').valueChanges()
}

Now in PurchaseComponent i am getting the complete information from the user and then calling above service to get the lastOrderNumber like this:

onOrderSubmit(formValue) {
  let orderNumber = this.orderService.getOrderNumber() +1;
  this.db.object('purchaseOrder/'+orderNumber).update(formValue);
}

Now getOrderNumberService returns a observable and it comes async and function execution is synchronously.

Any help how can i get constant value from the database, without using the observable or any other better approach.

NOTE for simplicity syntax might be little wrong, i hope actual problem scenario is explanatory.

Thanks in advance.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
Nutan Gwari
  • 205
  • 4
  • 9

0 Answers0