Completely external constants in Angular 5 using some configuration file

后端 未结 4 1074
小鲜肉
小鲜肉 2020-12-10 06:51

I have an app-const.ts with a server URL:

export class AppConst {
  public static serverPath = \'http://10.0.0.126:3031\';
}

This

4条回答
  •  粉色の甜心
    2020-12-10 07:23

    Another solution would be to add it as a javascript variable in your index.html file. I used this method and it works.

    Add it to the "head" part of your index.html with the "script" tags, example:

    
      
    ...
    

    (my global variable is named "LMS_REST_API_URL")

    After this you can access this variable like this:

    private lms_cli_URL = window["LMS_REST_API_URL"];
    

    I used it directly from the service that needs the URL, but it will probably also work in a seperate app-const.ts class file like you are using.

提交回复
热议问题