2

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?

Farhad
  • 533
  • 9
  • 21

1 Answers1

6

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

Farhad
  • 533
  • 9
  • 21
  • Any other suggestion or workaround would be appreciated and useful for community. Just to share angularfire2 issue #1240 (https://github.com/angular/angularfire2/issues/1240) or #1305 (https://github.com/angular/angularfire2/issues/1305) which I found them similar and interesting. – Farhad Aug 20 '18 at 04:25
  • No other idea and as it works then just I picked it up as answer for now. – Farhad Aug 28 '18 at 16:21