Posts

Showing posts from 2017

Simple Firebase service for Angular 2

If you want a very simple alternative to Angularfire you may create a firebase service very easily. I made this to avoid extra configuration when it comes to adding npm packages and configuring for bundling. This is done by downloading the scripts from Firebase CDN directly by using a dynamically created script tag.

Once the service is initialized you'll find the database in the public database property, and you just use the regular Firebase API. (Example: this.fbservice.database.ref('someproperty').set(somevalue) - and remember to have fbservice : FireBaseService in your component constructor to inject the service. )

And here's the code for the service:
import{Injectable}from'@angular/core';import{Observable}from'rxjs/Observable';declareconstfirebase : any;constconfig={apiKey:"",authDomain:".firebaseapp.com",databaseURL:"",storageBucket:".appspot.com",messagingSenderId:"",};@Injectable() exportclassFireB…