Is there an equivalent of Web.Config in Angular 4/5?

1

I have just started developing applications in Angular, for now the connection path with the BackEnd (for example: 192.169.1.114:8080) I have the app.module.ts. But I would like that path to be in some kind of configuration file type Web.Config of .Net, which exists when the dist was generated and to be able to go there to modify the path without having to generate the dist again.

Or if you know a better way to not have that path hardcodeado, I would be of great help the experience of someone who knows more the development in angular.

Thank you very much in advance community.

    
asked by Jesús Rojas 04.09.2018 в 17:45
source

1 answer

0

In the app/environment/ folder you will find 2 files called:

environment.prod.ts
environment.ts

Where environment.prod.ts will be the production configuration and environment.ts of development.

In development you would have something like:

export const environment = {
  production: false,
  url: '192.169.1.114:8080'
};

And in environment.prod.ts :

export const environment = {
      production: true,
      url: 'https:/urlproduccion.com/api/'
    };

Then in your code you import the object environment :

import { environment } from '../../environments/environment';

this.http.get(environment.url)
...

And angular CLI will know which to load according to the build type of the application if it is --prod or development.

    
answered by 04.09.2018 в 17:58