how to initilize the module with variable apiKey
See original GitHub issueI have the google api key in a singleton configuration service (a way to share the app configuration accross all the application).
How can I pass the apiKey variable the module inside @NgModule?
`@NgModule({
imports: [ BrowserModule, CommonModule, FormsModule, AgmCoreModule.forRoot({ apiKey: ‘YOUR_KEY’ // <-- I cannot use a constant!!! How can I pass a variable? }) ], providers: [], declarations: [ AppComponent ], bootstrap: [ AppComponent ] })`
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:12
Top Results From Across the Web
how to initilize the module with variable apiKey #882 - GitHub
I have the google api key in a singleton configuration service (a way to share the app configuration accross all the application).
Read more >how to initilize the module with variable apiKey - Bountysource
I have the google api key in a singleton configuration service (a way to share the app configuration accross all the application).
Read more >3.4 Hiding API Keys with Environment Variables (dotenv) and ...
In this lesson, we will address how to can hide an API key using environment variables and open source the code on GitHub....
Read more >initialize (Python agent API) - New Relic Documentation
Python API: Initializes Python agent with a specified config file during the manual integration process.
Read more >How to create module-wide variables in Python? [duplicate]
Here is what is going on. First, the only global variables Python really has are module-scoped variables. You cannot make a variable that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Depends on what kind of build tool you are using (e.g. angular-cli or custom webpack or …) and where the variable should come from. This can be a little tricky. Specially when you also want to use AOT compiling, which prevents too much dynamic code inside the
@NgModule
.The solution I currently implemented is overriding the ‘lazy config provider’ in my main app.module.
In the module where I actually use the map, I use an empty config in the forRoot:
In my app.module.ts: import the injection token:
Add to providers in
@NgModule
:And implement that ‘GoogleMapsConfig’ class, which should implement the
LazyMapsAPILoaderConfigLiteral
interface (from ’ from ‘angular2-google-maps/core/services’).In that injectable I can inject other services and read the config from somewhere. (e.g. if you use angular-cli you can import environments there). Or maybe read out the domain from the browser… or call an serverside API…
@jorrit-wehelp, thank you for your guidance. I am including below what is working for me…
in my main @ngmodule, I have this in providers…
The reference to the Config class is a build-time webpack variable-replace which setups of a map of variables used in Dev or Prod modes.