Last active
June 2, 2016 15:06
-
-
Save cdcarson/0961e152cc8f45d44b84ff4ada89be52 to your computer and use it in GitHub Desktop.
Bootstrapping a default Firebase app
This file contains hidden or 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 { OpaqueToken, Provider, provide } from '@angular/core'; | |
import * as firebase from 'firebase'; | |
export const FIREBASE_APP = new OpaqueToken('FIREBASE_APP'); | |
export const firebaseAppProvider = (config: Object): Provider => { | |
return provide(FIREBASE_APP, {useFactory: () => { | |
return firebase.initializeApp(config); | |
}}); | |
}; |
This file contains hidden or 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 { bootstrap } from '@angular/platform-browser-dynamic'; | |
import { provide } from '@angular/core'; | |
import { firebaseAppProvider } from './firebase/firebase-app.provider'; | |
import { AppComponent } from './app/app.component'; | |
bootstrap(AppComponent, [ | |
firebaseAppProvider({ | |
apiKey: "<APIKEY>", | |
authDomain: "<DOMAIN>.firebaseapp.com", | |
databaseURL: "https://<DOMAIN>.firebaseio.com", | |
storageBucket: "<DOMAIN>.appspot.com" | |
}) | |
]); |
This file contains hidden or 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, Inject } from '@angular/core'; | |
import { FIREBASE_APP } from '../../firebase/firebase-app.provider'; | |
import * as firebase from 'firebase'; | |
@Injectable() | |
export class SomeDataService { | |
// consume from the default app... | |
constructor(@Inject(FIREBASE_APP) public app: firebase.app.App) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment