Skip to content

Instantly share code, notes, and snippets.

@adnanmc
Created April 28, 2017 20:20
Show Gist options
  • Save adnanmc/8e6a147d2e8ac755a73ba57a0c548f73 to your computer and use it in GitHub Desktop.
Save adnanmc/8e6a147d2e8ac755a73ba57a0c548f73 to your computer and use it in GitHub Desktop.
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