无法使用 angularfire2 在 Angular 6 应用程序中访问多个 Google Firestore 数据库 [英] Can not have access to multiple Google Firestore DB in Angular 6 application with angularfire2
问题描述
我尝试通过 angularfire2 包从我的 Angular 6 应用程序访问多个 Google Firestore 数据库.
I try to have access to multiple Google Firestore DB from my Angular 6 application through angularfire2 package.
我在 app.module.ts 中初始化了多个 AngularFireModule 实例,但找不到访问两个数据库的方法:
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'),
...
],
...
})
有什么想法吗?
推荐答案
经过一番搜索,以下answer 可以提供很多帮助:angular2firebase - 使用 Angular 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 }
...
我创建了一个 stalkblitz 来展示它是如何工作的:https://stackblitz.com/edit/angular-or2ehb
I created a stalkblitz which shows how it works: https://stackblitz.com/edit/angular-or2ehb
这篇关于无法使用 angularfire2 在 Angular 6 应用程序中访问多个 Google Firestore 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!