Best way to override module values/constants in angularJS

前端 未结 3 2357
一个人的身影
一个人的身影 2021-02-20 07:03

I have written a module in angularJS that encapsulates all the backend communications. For greater flexibility I have the api prefix as a constant value on the module (could be

3条回答
  •  梦毁少年i
    2021-02-20 07:48

    Angular modules, controllers, etc. can be contained within functions, if-statements, etc. They do not have to be at the top level. So, you could include this in your code:

    if (environmentOne()) {
      module.value('apiPrefix','api1/data');
    } else {
      module.value('apiPrefix','api2/data');
    }
    

    Hope that helps!

提交回复
热议问题