Skip to content
Advertisement

Ionic pass in variable into library to Initialize firebase with

The solution consists of

  • One Ionic Solution
  • One Library called CoreLib

Problem

  • Initialize the firebase module inside the CoreLib with an injected variable from the ionic solution.

I can pass in a variable to the CoreLib library from the ionic solution no problem. Issue is, the AngularFireModule.initializeApp gets called before the injected variable can be used.

Any idea if its possible to use an injected variable to inialize the firebase module?

@NgModule({
  imports: [
    CommonModule,
     AngularFireModule.initializeApp(firebaseconfigVar),
  ],
  exports: [
  ],
})
export class SvcsFirebaseModule {
  code to inject a variable into some service here and to save the variable called 
  firebaseconfigVar
}

Advertisement

Answer

So, I learned something today

Even if you have a data layer consisting of X (in this case firebase) you don’t have to import and initialize firebase down the line in the library you are importing.

You can initialize firebase in your top most solution and that will trickle down to all your libraries.

So no need to pass down any Firebase credentials! Amazing!

Advertisement