Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created November 26, 2017 13:58
Show Gist options
  • Save gustavo-depaula/24ff69bb4810faf6db13c3fbc71602ef to your computer and use it in GitHub Desktop.
Save gustavo-depaula/24ff69bb4810faf6db13c3fbc71602ef to your computer and use it in GitHub Desktop.
Rate iPoo
ratesRef: AngularFireList<any>
rates: Observable<any[]>
constructor ( db: AngularFireDatabase ) {
this.ratesRef = db.list('bathrooms')
// Use snapshotChanges().map() to store the key
this.rates = this.ratesRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
})
alert(this.rates)
}
getRates () {
return this.rates
}
getRatesByBathroom (bathroomKey) {
return this.rates.filter(rate => rate.bathroomKey === bathroomKey)
}
addRate (data) {
this.ratesRef.push(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment