Created
April 28, 2017 20:20
-
-
Save adnanmc/8e6a147d2e8ac755a73ba57a0c548f73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AngularFire, FirebaseListObservable } from 'angularfire2'; | |
import 'rxjs/add/operator/map'; | |
import { Business } from '../Business'; | |
import { Category } from '../Category'; | |
@Injectable() | |
export class FirebaseService { | |
businesses: FirebaseListObservable<Business[]>; | |
categories: FirebaseListObservable<Category[]>; | |
constructor(private _af: AngularFire){ | |
} | |
getBusinesses(category:string = null){ | |
if (category !== null) { | |
this.businesses = this._af.database.list('/businesses', { | |
query: { | |
orderByChild: 'category', | |
equalTo: category | |
} | |
}) as FirebaseListObservable<Business[]>; | |
} else { | |
this.businesses = this._af.database.list('/businesses') as FirebaseListObservable<Business[]>; | |
} | |
return this.businesses; | |
} | |
getCategories(){ | |
this.categories = this._af.database.list('/categories') as FirebaseListObservable<Category[]>; | |
return this.categories; | |
} | |
addBusiness(newBusiness){ | |
return this.businesses.push(newBusiness); | |
} | |
updateBusiness(key, updBusiness){ | |
this.businesses.update(key, updBusiness); | |
} | |
deleteBusiness(key){ | |
this.businesses.remove(key); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment