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