How to add a module and make it available for angular application

I have a module (app.config) that I would like to add with my entire application.

The module must be available in all other modules embedded in the application.

For example, my application looks like this:

angular.module('myApp', [
    'app.config',
    'module#1',
    'module#2',
    'module#3',
    'module#4'    
])
.config...

/////////////////////////////////

Here app.config

angular.module('app.config', []).
    constant('NAME1', 'Name1').
    constant('NAME2', 'Name2'); 
////////////////////

I want "app.config" to be entered so that it can be accessed in all modules (module # 1 ',' module # 2 ', ....).

Here is my problem:

angular.module('module#1', []).
    service('serviceOne', serviceOne);

function ServiceOne($http) {

    var service = {
        getMyProfile: function(){return $http.get('api/' + NAME1);}
    };

    return service;
}

Problem → NAME1 - undefined. But I thought I introduced it to the whole application.

I do not want to individually add app.config to each module. Any other solutions?

+2
3

.

function ServiceOne($http, NAME1) {

   var service = {...
   ...

 }

+3

NAME1 - , Angular , , ! , , ( , 'app.config') 'Module1'. , , this, , , . , , . :

var mod1 = angular.module('Module1', ['app.config']);

mod1.service('ServiceOne', ['$http', 'NAME1', serviceOne]);

function ServiceOne($http, NAME1) {

  this.getMyProfile = function() {
    return $http.get('api/' + NAME1);
  };

}
0

app.config

module.exports = {
    NAME1: 'Name1',
    NAME2: 'Name2'
}

var config = require('../config');

angular.module('module#1', []).
    service('serviceOne', serviceOne);

function ServiceOne($http) {

    var service = {
        getMyProfile: function(){return $http.get('api/' + config.NAME1);}
    };

    return service;
}
0

All Articles