如何注入模块,并使其向入店角entrie应用 [英] How to inject module and make it accesible to entrie angular app

查看:173
本文介绍了如何注入模块,并使其向入店角entrie应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块的(的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 = {...
   ...

 }

在这里是一个很好的解释

这篇关于如何注入模块,并使其向入店角entrie应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆