how to inject API_BASE_URL (a string) in an angular service

后端 未结 3 1840
小鲜肉
小鲜肉 2021-01-01 21:31

this autogenerated service (by NSwagStudio) needs an API_BASE_URL (InjectionToken) value in order to perform http requests how and where i can inject it?

/*         


        
3条回答
  •  不思量自难忘°
    2021-01-01 21:49

    THe best practice to put all constants in environment.ts and environment.prod.ts. Just create a new property their and import in your service. Your code will look like this:

    // environment.ts
    export const environment = {
      production: false,
      API_BASE_URL: "baseUrlOfApiForDevelopment",
    };
    
    // environment.prod.ts
    export const environment = {
      production: false,
      API_BASE_URL: "baseUrlOfApiForProduction",
    };
    

    Now you need to import in your service to use it.

提交回复
热议问题