angularjsangularjs-factoryangularjs-module

How to use module function inside another factory in angularjs


I have configurations.js file which having

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

and having another javascript file with below code

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

Actually i want function configSvc.getConfig inside second angular factory


Solution

  • Yes After tired of trying lots of solution, today morning working on moving train got idea to fix, dont know if its correct way but its working. but still looking for correct fix if mine was not correct as per angularjs practise.

    Here is my solution. 1. I added configuration module in app.js alogn with other

    window.app = angular.module('ds.app', [
                'restangular',
                'ui.select',
                'ui.router',
                'ds.shared',
                'ds.utils',
                'ds.i18n',
                'configuration']);
    
    1. I added clientConfigSVC in my factory where i want to use configuration function

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

    and then inside CouponsREST factory with function clientConfig.getConfig() i am getting value