热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

FirebaseAngular4根据节点环境进行初始化-FirebaseAngular4Initializebasedonnodeenvironment

IvebuiltmyAngular4projectusingtheAngularCLI.IamdeployingmyapponHeroku,Ivecreated

I've built my Angular 4 project using the Angular CLI. I am deploying my app on Heroku, I've created heroku pipelines for dev and production environment. I have two firebase database dev and production and I want my angular 2 apps to connect to the firebase database based on heroku config variables

我使用Angular CLI构建了我的Angular 4项目。我正在Heroku上部署我的应用程序,我已经为开发和生产环境创建了heroku管道。我有两个firebase数据库开发和生产,我希望我的angular 2应用程序基于heroku配置变量连接到firebase数据库

I searched on google and found this answer helpful as @yoni-rabinovitch suggested to send an HTTP request on node server to check for the environment when the app initializes.

我在谷歌搜索并发现这个答案很有帮助,因为@ yoni-rabinovitch建议在节点服务器上发送HTTP请求,以便在应用初始化时检查环境。

I am a beginner in Angular 4 and typescript and all I need to implement is to send an HTTP request and initialize the firebase module based on the response.

我是Angular 4和typescript的初学者,我需要实现的是发送HTTP请求并根据响应初始化firebase模块。

app.module.ts

app.module.ts

import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    AngularFireModule.initializeApp(environment.firebase)
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Any help would be highly appreciated

任何帮助将受到高度赞赏

1 个解决方案

#1


0  

You can create a function to receive the configuration:

您可以创建一个函数来接收配置:

import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    AngularFireModule.initializeApp(AppModule.getFirebaseConfig())
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
  static getFirebaseConfig(): FirebaseAppConfig {
    // do http request

    // return correct correct configuration depending on http request
    return environment.firebase;
  }
}

推荐阅读
author-avatar
谷智精源
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有