I'm trying to inject a variable into forRoot({[...]})
method of an Angular module.
I got this variable in an asynchronous way, so I tried to get it before bootstrap Angular. (It comes from cordova.js)
The problem:
It seems that Angular import the modules (and call the 'forRoot' methods) before being bootstrapped.
Is there a way to achieve this ?
Thanks !
An example of what I tried:
app.module.ts
import {NgModule} from '@angular/core';
import {AgmCoreModule} from '@agm/core';
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: window['device'].platform, // value is 'null' instead of 'browser' or something else
libraries: ['places']
})
],
// [...]
bootstrap: [AppComponent]
})
export class AppModule {
}
src/main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
document.addEventListener('deviceready', () => {
console.log(window['device'].platform); // log 'browser'
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
}, false);
/!\ Tips
The library I'm using (@agm/core) expect a string as apiKey, and not a function...