How to config different development environment in Angular 2 app

后端 未结 5 759
遇见更好的自我
遇见更好的自我 2020-12-08 04:37

I have a constant file

export class constants {
    public static get API_ENDPOINT(): string { return \'https://dvelopment-server/\'; }
}

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 04:48

    I would just like to add put some more light into the answer provided by @Cartucho. He is right about the steps required to setup a personalized environment for your angular 2 apps. I would also like to second the opinion that the article at Guide to Build the app in different environments

    But the given article misses out on an important step. Steps to set up a personalized environment are as follows: 1) Create a new file called environment.YourEnvName.ts in the environments folder in the project. 2) Add the Environment description in the "environments" object in the angular-cli.json file.

    "environments": {
        "source": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "dev": "environments/environment.dev.ts", 
        "qa": "environments/environment.qa.ts",
        "YourEnvName": "environments/environment.YourEnvName.ts"
      }
    

    3) Once you have made these changes you can build the app for your new environment using the following command.

    ng build --environment=YourEnvName or 
    
    ng serve --environment=YourEnvName 
    

    Hope this post is helpful to any new Angular 2 developer.

提交回复
热议问题