registerModule与依赖关系 [英] registerModule with dependencies

查看:277
本文介绍了registerModule与依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建设有MEAN.JS一个应用程序,我想从另一个模块使用的控制器。我发现我可以依赖注入做到这一点:

I'm building an app with MEAN.JS and I'm trying to use a controller from another module. I've found that I can do this with dependency injection:

angular.module(‘MyModule’, [‘Dependency’]);

但模块在MEAN.JS创建的方式是:

But the way modules are created in MEAN.JS is:

ApplicationConfiguration.registerModule('MyModule');

和我不能只传递第二个参数 registerModule 。所以,我应该怎么办呢?我一定要使用这两种方法?我是不是做错了?

And I can't just pass a second parameter to registerModule. So, how should I do this? Do I have to use both methods? Am I doing it wrong?

我想添加一个新的模式:广告系列广告仅由管理员创建的,但可以通过活动所有者可以看出(另一个用户)。在创建活动表格应列出可用的用户,因此管理员可以选择的将是该广告系列的所有者的人。结果
问题是,在创建活动形式是由 CampaignsController 控制的,我怎么能列出用户?我用另一个控制器( UsersController )和多数民众赞成这个问题,这是不确定的,因为我们是在广告系列模块。

I want to add a new model: Campaign. Campaigns are created by admins only, but can be seen by the "campaign owner" (another User). The create campaign form should list available Users, so the admin can select the one that's going to be the "owner" of that Campaign.
The problem is, the create campaign form is controlled by CampaignsController, how can I list Users? I've used another controller (UsersController) and thats the problem, it is undefined because we are in the Campaign module.

问题是咕噜autorestarting应用程序错误:结果
我从一个模块(文件夹)移动到另一个控制器,但咕噜仍在努力从旧的路径加载它,因而失败:控制器未找到。我认为这个问题是依赖注入,但你只有关闭​​咕噜(Ctrl + C键),然后再次运行它。问题解决了。结果
不管怎么说,感谢您的回答@gilBirman导致它是正确的:没有必要注入与MEANJS什么

The problem was grunt autorestarting the app incorrectly:
I moved the controller from one module (folder) to another, but grunt was still trying to load it from the old path, and thus failing: Controller not found. I thought the problem was dependency injection, but you only have to close grunt (Ctrl+C) and run it again. Problem solved.
Anyways, thanks for the answer @gilBirman cause it is correct: there is no need to inject anything with MEANJS.

推荐答案

MEAN.js使所有通过 registerModule 注册模块提供给所有其他模块的应用可以将其作为一个依赖于主被叫应用的的意思是。下面是做到这一点的MEAN.js源$ C ​​$ C部分:

MEAN.js makes all the modules registered via registerModule available to all other modules in your app by adding it as a dependency to the main app called mean. Here's the part of the MEAN.js source code that does this:

var applicationModuleName = 'mean';
....
// Add a new vertical module
var registerModule = function(moduleName) {
    // Create angular module
    angular.module(moduleName, []);

    // Add the module to the AngularJS configuration file
    angular.module(applicationModuleName).requires.push(moduleName);
};

所以你在正确的轨道上,但它听起来像你想的注入控制器的。然而,的角度,控制器不注射。你可以注入的服务工厂常量

So you're on the right track, however it sounds like you are trying to inject a controller. However, in angular, controllers are not injectable. You can inject services, factories, values, and constants.

这篇关于registerModule与依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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