In Ionic 3 with Angular 5 I am trying to define all my external API keys inside an app.config.ts
file.
I must declare a class otherwise I get an AOT error raised by ngc.
Here is my app.config.ts
import { Injectable } from '@angular/core';
@Injectable()
export class AppConfig {
public ONESIGNAL_API_KEY: string;
public FIREBASE_CONFIG: any;
public MIXPANEL_TOKEN: string;
constructor() {
this.ONESIGNAL_API_KEY = 'myoskey';
this.FIREBASE_CONFIG = {
apiKey: "myfbkey",
authDomain: "myfbdomain
};
this.MIXPANEL_TOKEN = 'mymptoken';
}
}
I can inject it in constructors of other classes but firebase must be initialize in app.module.ts
. So I tried to do the following
// Config
import {AppConfig} from './app-config';
...
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(MyApp, {
backButtonText: '',
tabsHideOnSubPages: true,
//scrollAssist: true,
//autoFocusAssist: true
}),
IonicStorageModule.forRoot(),
IonicImageLoader.forRoot(),
AngularFireModule.initializeApp(AppConfig.FIREBASE_CONFIG),
....
Unfortunately I get the following error
Property 'FIREBASE_CONFIG' does not exist on type 'typeof AppConfig'.
How can declare FIREBASE_CONFIG
within this app.config
file and directly use it in app.module
?
I tried to directly initialize the variable before the constructor like this, but same result
import { Injectable } from '@angular/core';
@Injectable()
export class AppConfig {
public ONESIGNAL_API_KEY: string;
public FIREBASE_CONFIG: any = {
apiKey: "myfbkey",
authDomain: "myfbdomain
};
public MIXPANEL_TOKEN: string;
constructor() {
this.ONESIGNAL_API_KEY = 'myoskey';
this.MIXPANEL_TOKEN = 'mymptoken';
}
}
Any idea?