首页 > 最新热文 > 计算机探索

如何注入模块,并使其向入店角entrie应用使其、模块、entrie、入店角

2023-09-14 23:10:55 作者:和她爱个够

我有一个模块的(的app.config),我想注入我的整个应用程序。

I have a module (app.config) that I would like to inject my entire app.

的模块需要注入应用

例如,我的应用程序是这样的:

For example, my app looks like this:

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

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

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

这里的app.config

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

我想以这样的方式,它可以全部模块内被访问注入'的app.config'(模块#1,模块#2',....)以及

I want 'app.config' injected in such a way that it can be accessed inside all modules (module#1','module#2',....) as well.

这里是我的问题:

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

function ServiceOne($http) {

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

    return service;
}

问题 - > NAME1是未定义但是我想我是注入到整个应用程序???

Problem -> NAME1 is undefined. But I thought I injected it to the entire app???

我不想单独注入的app.config给每个模块。任何其他解决办法?

推荐答案

您需要注入到控制器中的常数也。

you need to inject the constants in to the controller as well.

function ServiceOne($http, NAME1) {

   var service = {...
   ...

 }

在这里是一个很好的解释

相关文章
猜你喜欢
精彩推荐