Search code examples
angularfirebaseangularfire2angularfire

How can I connect two databases with @angular/fire?


I'm trying to connect to firestore databases to my angular frontent. I've tried by adding a secound AngularFireModule, with no success!

@NgModule({
  declarations: [AppComponent], // Autosize
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicRatingModule, // Put ionic-rating module here
    AppRoutingModule,

    ReactiveFormsModule,
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireAuthModule,
    AngularFirestoreModule,
    AngularFireStorageModule,
    AngularFireFunctionsModule,
  ],
  providers: [
    StatusBar,
    AuthenticatedGuard,
    ProducerGuard,
    AdminGuard,
  ],
  bootstrap: [AppComponent]
})

I'm using @agular/fire version 5.2.3 And angular version 7 Thanks!


Solution

  • Your question is a potential duplicate of :

    Please have a look also at these 2 issues on GitHub :

    And this stackblitz made by Farhad on previous items.

    As it is mentioned in answers above, you can manually provide multiples instances of Firestore inside NgModule:

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