实际上,我这样硬编码Web API调用:

$http.get('my/production/web/api/method');


如果要切换到另一个Web API测试环境,则不想手动更改代码中的每个硬编码调用。

有没有一种方法可以通过使用配置文件来解决此问题,或者具有angularjs的功能来处理该问题?

最佳答案

就像domakas所说的,使用您自己的配置文件:

var config={
   environment:'production'
   //environment:'dev'
};

$http.get('my/'+config.environment+'/web/api/method');


发挥自己的作用:

function queryWebApi(method) {
    $http.get('my/'+config.environment+'/web/api/'+method);
}

07-24 17:50
查看更多