pass angularFire config imported in library using forRoot

依然范特西╮ 提交于 2019-12-06 14:26:11

问题


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:


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.



来源:https://stackoverflow.com/questions/49776296/pass-angularfire-config-imported-in-library-using-forroot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!