采用了棱角分明的$编译时脚本标记添加控制器 [英] Adding controller in script tag when using angular's $compile

查看:160
本文介绍了采用了棱角分明的$编译时脚本标记添加控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$编译 -ing角度HTML模板字符串我试图把额外的控制器和指令&LT内部;脚本&GT ; 标记并使用那些在HTML模板

When $compile-ing an angular HTML template string I'm trying to put additional controllers and directives inside a <script> tag and use those in the HTML template.

这个办法,我基本上是想实现某种插件机制的,这样我可以加载增强我的应用程序的功能外部文件。

This way I'm essentially trying to implement some sort of plug-in-mechanism, so that I can load external files that augment my app's functionality.

&LT;脚本&GT; 标记不会真正得到评估,但我的问题是,HTML模板编译发生JavaScript的评价了。所以编译器会抱怨缺少的控制器。

The <script> tag does actually get evaluated, but my problem is, that the HTML template compilation takes place before the evaluation of the JavaScript. So the compiler complains about missing controllers.

例如:

http://plnkr.co/edit/8oZYhRHAjP84ecnl6hG3?p=$p$ PVIEW

这个例子抛出一个错误:错误:参数'控制'不是一个函数,得到了不确定

This example throws an error: Error: Argument 'Controller' is not a function, got undefined

如果您删除线15-18 app.js (引用创建的电脑板的HTML),您可以在创建控制器这样做控制台中看到实际工作。

If you delete lines 15-18 (the HTML that references the created conroller) in app.js, you can see in the console that creating a controller this way does actually work.

推荐答案

我终于根据<一个解决方案做href=\"http://stackoverflow.com/questions/15250644/angularjs-loading-a-controller-dynamically\">AngularJS:加载控制器动态的。
THX @JoseM,@MaximShoustin和@JussiKosunen你的提示和帮助。

I finally managed to do it based on the solution in AngularJS: Loading a controller dynamically. Thx @JoseM, @MaximShoustin and @JussiKosunen for your hints and help.

http://plnkr.co/edit/fzmEZlP6bGBJqTOkfApH?p=$p$ PVIEW

这篇关于采用了棱角分明的$编译时脚本标记添加控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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