1

I use angularFire2 in a custom library

@NgModule({ imports: [ CommonModule, AngularFireModule.initializeApp(firebaseConfig), AngularFirestoreModule ] }) export class CustomModule { static forRoot(firebaseConfig: FirebaseOptions): ModuleWithProviders { return { ... } } } 

the consumer library call CustomModule.forRoot({config...})

My question is how do I make the config data available in AngularFireModule.initializeApp(firebaseConfig) ?

1 Answer 1

3

I ran into this problem couple of weeks ago, what you have to do is drop the initializeApp call in the imports section, and add the FirebaseOptionsToken to your forRoot declaration like below:

@NgModule({ imports: [ CommonModule, AngularFireModule, AngularFirestoreModule ] }) export class CustomModule { static forRoot(firebaseConfig: FirebaseOptions): ModuleWithProviders { return { ngModule: CustomModule, providers: [ { provide: FirebaseOptionsToken, useValue: firebaseConfig } ] } } } 

If you look at the initializeApp method in Angular/Fire you see how it does the same thing when it is called.

It worked for me, hopefully will help others having the same issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @jair Milanes, I ran into the same situation and your solution just works.
And change FirebaseOptionsToken to FIREBASE_OPTIONS in newest version...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.