Bird
0
0

How can you configure different API endpoints for development and production in an Angular project?

hard📝 Application Q9 of 15
Angular - Fundamentals
How can you configure different API endpoints for development and production in an Angular project?
ASet URLs in package.json scripts
BHardcode URLs in app.component.ts and switch manually
CStore URLs in src/assets/api.json and read at runtime
DUse src/environments/environment.ts and environment.prod.ts with file replacements in angular.json
Step-by-Step Solution
Solution:
  1. Step 1: Identify environment config usage

    Angular uses environment.ts files for different builds, replaced via angular.json settings.
  2. Step 2: Reject other options

    Hardcoding is error-prone, assets are static files not config, package.json scripts don't manage runtime URLs.
  3. Final Answer:

    Use src/environments/environment.ts and environment.prod.ts with file replacements in angular.json -> Option D
  4. Quick Check:

    Environment files + angular.json file replacements manage API URLs [OK]
Quick Trick: Use environment files and angular.json for API URL switching [OK]
Common Mistakes:
  • Hardcoding URLs in components
  • Using assets folder for config
  • Trying to set URLs in package.json

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes