【问题标题】:How to change configuration variables in Ionic app when building/testing构建/测试时如何更改 Ionic 应用程序中的配置变量
【发布时间】:2016-06-23 22:38:41
【问题描述】:

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

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

定义这两组(或更多)变量的推荐方法是什么,以及如何将其合并到构建工作流程中?

【问题讨论】:

    标签: javascript angularjs ionic-framework gulp


    【解决方案1】:

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

    假设您的 app.js 中有这些行

    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
    });
    

    祝你好运

    【讨论】:

      猜你喜欢
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2016-04-17
      • 2016-08-29
      • 1970-01-01
      相关资源
      最近更新 更多