How to store the root url of api in angular 4 app?

后端 未结 7 1498
Happy的楠姐
Happy的楠姐 2020-12-29 03:16

I followed the official tutorials and made services for the Apis but absolute url of the Api is hardcoded in services.

I want to keep the base url of Api somewhere s

7条回答
  •  无人及你
    2020-12-29 03:57

    Use the environment files

    If youre using the cli you should use the environment files. By configuring the angular-cli.json file you can manage all the available environments and create new ones. For example you could create an environment.dev.js file and store the values there, by making git ignore it any member in your team can have a customized one.

    Said environment file will overwrite the original environment.js

    See this SO answer angular-cli for angular2 how to load environment variables

提交回复
热议问题