This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2722|Reply: 0

[Angular] Angular 18 series (twenty) environment variables are used by Environments

[Copy link]
Posted on 8/2/2024 9:35:11 AM | | | |
Requirements: Project releases generally include development, testing, production and other environments, each environment may have different configuration information, such as: interface address, key and other information are inconsistent, how to compile and generate different release packages through the configuration of the environment variable Environments, andYou don't need to change your code every time you switch to a different environment

Create a configuration file using angular-cli scaffolding with the following command:

The command creates two files:

  • src/environments/environment.ts
  • src/environments/environment.development.ts


At the same time, the configuration in angular.json will also be modified, as follows:



The project's src/environments/ directory contains the base configuration file, environment.ts which provides configurations for the default production environment.

environment.tsThe configuration is as follows:

environment.development.tsThe configuration is as follows:

When the project needs to use the environment configuration, only references are neededimport { environment } from '.. /environments/environment';Can.

Use the development and production environments to start the test separately with the following command:

As shown below:



Reference:The hyperlink login is visible.





Previous:Prettier is a front-end tool to beautify and format your code
Next:Angular 18 Series (21) Router Routing Change Events
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com