Burst of Ice
Burst of Ice

Reputation: 386

AngularFire get and set a single value from/to a firebase database

My firebase database is called verhuurfietsen and I have a maximum amount of 4 which I want to get and set but still the maximum has to be 4.

firebase

 obj;
 constructor(private db: AngularFireDatabase){}
 ngOnInit() {
  this.obj = this.db.database.ref('amount');
 }

 updateMaxValue(){
  this.obj.update(this.max)
 }

pushing is not an issue but I can't seem to find anywhere how you get a single value out of a firebase database. I want to initialise my max variable with the valure from the firebase db

Upvotes: 0

Views: 1220

Answers (1)

Hareesh
Hareesh

Reputation: 6900

Try in Angularfire2 way

ngOnInit() {
  this.db.object('amount').valueChanges().subscribe(action => {
      console.log(action);
      for(var obj in action) { 
          console.log(obj); 
          this.max = Number.parseInt(obj);
      }
    });
}

Upvotes: 1

Related Questions