Firebase Angular 4基于节点环境进行初始化 [英] Firebase Angular 4 Initialize based on node environment

查看:165
本文介绍了Firebase Angular 4基于节点环境进行初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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



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



app.module.ts

从../environments/environment导入 import {environment}; 
$ b @NgModule({
声明:[
AppComponent
],
进口:[
BrowserModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
AngularFireModule.initializeApp(environment.firebase)
],
bootstrap:[AppComponent]
})
export class AppModule {}

任何帮助将不胜感激

解决方案

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

 从../environments/environment导入{environment}; 
$ b @NgModule({
声明:[
AppComponent
],
进口:[
BrowserModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
AngularFireModule.initializeApp(AppModule.getFirebaseConfig())
],
bootstrap:[AppComponent]
})
export class AppModule {
static getFirebaseConfig():FirebaseAppConfig {
// do http请求

//根据http请求返回正确的正确配置
return environment.firebase;
}
}


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

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.

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.

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

解决方案

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;
  }
}

这篇关于Firebase Angular 4基于节点环境进行初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆