Prepare for Angular Interviews with real-life questions. Utilize quizzes and examples to deepen understanding and enhance your skills. Gear up to ace your interview!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How can you specify a different environment configuration when serving an Angular application?

  1. By using the --env flag with ng serve

  2. By using the --configuration flag with ng serve

  3. By modifying the environment.ts file directly

  4. By creating a new build configuration in angular.json

The correct answer is: By using the --configuration flag with ng serve

The ability to specify a different environment configuration when serving an Angular application is accomplished by using the --configuration flag with ng serve. This method allows developers to choose from predefined configurations set in the angular.json file. Each environment configuration typically includes different settings tailored for development, staging, production, etc., influencing aspects like API endpoints and feature flags relevant to each environment. For example, if you have different configurations for production and development, the command `ng serve --configuration production` would apply the settings defined under the production configuration, allowing the application to run with those specifications seamlessly. This approach ensures that developers can test how the application behaves under various environments without the need for manual changes to the environment files each time they switch contexts. While modifying the environment.ts file directly might change configurations, this approach doesn’t offer the flexibility to easily switch between multiple configurations during development. Creating new build configurations in angular.json could also require additional setup and is not the immediate method to serve with a different configuration. Therefore, utilizing the --configuration flag is the standard and more efficient way to manage and test various environment setups in an Angular application.