如何在构建/测试时更改Ionic应用程序中的配置变量

时间:2016-06-23 22:38:42

标签: javascript angularjs ionic-framework gulp

我不熟悉gulp工具,所以我不确定这是否可以解决这个问题。

我有一个离子应用程序,在其结构中使用app.js文件中定义的一些全局配置变量。当导出用于测试的应用程序(离子服务)时,这些变量可以具有特定值,例如执行请求的服务器等,当导出到设备时,这些变量应该设置不同。

建议如何定义这两组(或多组)变量以及如何将其合并到构建工作流程中?

1 个答案:

答案 0 :(得分:1)

我不知道我是否理解你......所以我向你提供了我的解决方法

假设您有app.js theese行

angular.module('app', ['ionic'])
  /* if mobile */
    .value('mobile', 'some_config_mobile')
  /* if destkop */
    .value('desktop', 'some_config_desktop')

在您的控制器/服务中,您可以这样做

 angular.module('app')
    .service('myService', function (desktop,mobile){
       var config = (ionic.Platform.isWebView()) ? mobile : desktop; 
       //note: isWebView === true ---> you are in mobile
       //now you can use config wherever you are testing your app
});
祝你好运