角动态地注入模块依赖 [英] Angular Dynamically Inject Module Dependency

查看:118
本文介绍了角动态地注入模块依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一把umbraco使用角一个评论插件。因此对于网站主的角度应用程序有注入评论系统模块为它​​工作。

I've developed a commenting plugin for Umbraco that uses angular. As such the main angular app for the site has to inject the comment systems module for it to work.

例如

var theirSite = angular.module('someApp', []);

注射

var theirSite = angular.module('someApp', ['theCommentSystemModule'];

在我的评论系统,

   angular.module('theCommentSystemModule']....;

有什么办法我的模块可以自动检测角应用程序,并没有code表示具有网站上植入本身进行更新?我希望它只是不过是脚本链接工作。

Is there any way my module can automatically detect the angular app and inject itself without the code for the site having to be updated? I want it to just work with nothing but the script link.

例如:说的这些都是剧本

For Example: say these are the scripts

<script src="...angular.js">
<script src="...services.js">
<script src="...directives.js">
<script src="...commentsPlugin.js">
<script src="...theirApp.Js">

所以我基本上需要,是某种来自角回调的应用程序正在被自举的时候,这样我就可以注入评论系统模块插入应用作为depedency模块,以便将其引导层初始化。

So what I basically need, is some kind of callback from angular when the app is being bootstrapped, so I can inject the comment systems module into the app as a depedency module so that it will initialize in their bootstrap layer.

也许,或者,我自己引导的页面在插件本身?哪有同时运行,例如两个应用程序如果我引导和他们的应用程序也引导的。

Or maybe, alternatively, I bootstrap the page myself in the plugin for itself? Can there be two apps running at once, e.g. if I bootstrap and their app also bootstrap's .

推荐答案

可以通过使用无证的要求模块属性。这种方式新的依赖的模块后,它被定义,但它是bootstapped了。

It can be done by using undocumented requires module property. This way new dependencies can be added to the module after it was defined but before it was bootstapped.

由于'NG'是唯一已知的和定义的模块自动柜员机(它也已经定义了要求数组),它篡改:

Since 'ng' is the only known and defined module ATM (it also has already defined requires array), tamper it:

angular.module('ng').requires.push('theCommentSystemModule');

虽然它是比较合适的,让用户自行加载模块。

Though it is more appropriate to let the users load the module by themselves.

这篇关于角动态地注入模块依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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