【问题标题】:How to use module function inside another factory in angularjs如何在angularjs的另一个工厂中使用模块功能
【发布时间】:2019-06-11 19:26:36
【问题描述】:

我有

的configurations.js 文件
var configurationModule = angular.module('configuration', ['restangular', 'notification']);
configurationModule.factory('clientConfigSvc', function (notificationMgr, $interpolate, $injector) {
      function getConfig(configKey) {
        return getNestedPropertiesByString(activeEnvironment, configKey);
      }
}

并拥有另一个带有以下代码的 javascript 文件

angular.module('ds.coupons').factory('CouponsREST', ['Restangular', 'SiteConfigSvc', 'settings',function (Restangular, siteConfig, settings, configurationModule) {
  configSvc.getConfig('services.baseUrl'); /// need to call this function
}

其实我想要函数 configSvc.getConfig 在第二个角度工厂中

【问题讨论】:

    标签: angularjs angularjs-factory angularjs-module


    【解决方案1】:

    是的 在厌倦了尝试很多解决方案之后,今天早上在移动火车上工作的想法得到了解决,不知道它是否正确,但它的工作原理。但如果我的按照 angularjs 实践不正确,仍然在寻找正确的解决方法。

    这是我的解决方案。 1.我在app.js中添加了配置模块与其他的logn

    window.app = angular.module('ds.app', [
                'restangular',
                'ui.select',
                'ui.router',
                'ds.shared',
                'ds.utils',
                'ds.i18n',
                'configuration']);
    
    1. 我在工厂中添加了clientConfigSVC,我想使用配置功能

      angular.module('ds.coupons') .factory('CouponsREST', ['Restangular', 'SiteConfigSvc','settings', 'clientConfigSvc', 功能(Restangular,siteConfig,设置,clientConfig){}

    然后在带有函数 clientConfig.getConfig() 的 CouponsREST 工厂中,我得到了价值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 2014-11-19
      • 2016-05-30
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多