Can not have access to multiple Google Firestore DB in Angular 6 application with angularfire2

可紊 提交于 2019-12-21 22:41:58

问题


I try to have access to multiple Google Firestore DB from my Angular 6 application through angularfire2 package.

I initialized multiple instance of AngularFireModule in app.module.ts but couldn't find a way to have access to both DBs:

  @NgModule({
  declarations: [
	...
  ],
  imports: [
	...
    AngularFireModule.initializeApp(coolStoreConfig, 'coolStore'),
    AngularFireModule.initializeApp(perfectStoreConfig, 'perfectStore'),
	...
  ],
  ...
 })

Any idea?


回答1:


After some searches around, the following answer could help a lot: angular2firebase - multiple instances using Angular 6

looks like creating providers for each instance can be a good idea

...
{ provide: AngularfirestoreCoolStoreService, deps: [PLATFORM_ID, NgZone], useFactory: AngularfirestoreCoolStoreFactory },
{ provide: AngularfirestorePerfectStoreService, deps: [PLATFORM_ID, NgZone], useFactory: AngularfirestorePerfectStoreFactory }
...

I created a stalkblitz which shows how it works: https://stackblitz.com/edit/angular-or2ehb



来源:https://stackoverflow.com/questions/51922195/can-not-have-access-to-multiple-google-firestore-db-in-angular-6-application-wit

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