How do you handle environment-specific settings in Angular?
Model answer
Keep settings, such as the API base URL, out of components. Common approaches: environment files replaced at build time with fileReplacements, a configuration loaded at startup (for example from a JSON file fetched with provideAppInitializer), or an InjectionToken that holds the config.
Never put secrets such as API keys or private tokens in front-end code, because anything in the bundle can be read by users. Keep secrets on the server.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- How do you write a unit test for a component or a service in Angular?
- What is the difference between unit, integration and end-to-end tests?
- How do you test a component that calls an API?
- How do you test route guards, pipes and directives?
- What does ng lint and a formatter give you, and what other tooling do Angular teams use?
- How would you structure a large Angular application?