我为Umbraco开发了一个使用角度的评论插件.因此,该站点的主要角度应用程序必须注入注释系统模块才能工作.
例如
var theirSite = angular.module('someApp', []);
Run Code Online (Sandbox Code Playgroud)
注射
var theirSite = angular.module('someApp', ['theCommentSystemModule'];
Run Code Online (Sandbox Code Playgroud)
在我的评论系统中,
angular.module('theCommentSystemModule']....;
Run Code Online (Sandbox Code Playgroud)
有什么方法我的模块可以自动检测角度应用程序并注入自己,而不需要更新站点的代码?我希望它只使用脚本链接.
例如:说这些是脚本
<script src="...angular.js">
<script src="...services.js">
<script src="...directives.js">
<script src="...commentsPlugin.js">
<script src="...theirApp.Js">
Run Code Online (Sandbox Code Playgroud)
所以我基本上需要的是在应用程序被引导时从角度进行某种回调,因此我可以将注释系统模块作为依赖模块注入应用程序,以便它将在其引导层中初始化.
或者,也许,或者,我自己在插件中自己引导页面?可以同时运行两个应用程序,例如,如果我引导它们的应用程序也是bootstrap的.
Est*_*ask 10
可以使用未记录的requires模块属性来完成.这样,新的依赖项可以在定义之后但在引导之前添加到模块中.
由于'ng'是唯一已知和定义的模块ATM(它也已经定义了requires数组),因此篡改它:
angular.module('ng').requires.push('theCommentSystemModule');
Run Code Online (Sandbox Code Playgroud)
尽管让用户自己加载模块更合适.