0

我有一个自定义指令,它添加了一些 html。

myAppModule.directive('myDirective', function() {
    var linker = function(scope, element) {
        return element.html("<b>directive loaded</b>");
    };
    return {
        restrict: "E",
        rep1ace: true,
        link: linker,
        scope: false
    };
});

该指令在动态加载的 html 中加载和使用,该 html 包含在ng-include.

<script type="text/javascript" src="dynamicscript.js"></script>
<my-directive>...</my-directive>

但它不起作用。-functionlinker永远不会被调用。如果我将dynamicscript.js脚本加载从包含的 html 移动到index.html.

这是Plunkr

4

2 回答 2

2

只需使用RequireJS加载控制器、指令等。

使用特殊插件,也可以加载 CSS 和 HTML 文件。

这是 Ben Nadel 的一个很好的例子:http ://www.bennadel.com/blog/2554-Loading-AngularJS-Components-With-RequireJS-After-Application-Bootstrap.htm

于 2013-11-25T14:29:08.500 回答
0

所有 JS 文件都应包含在 'index.html' 中 使用 ng-include 动态加载的 JS 文件(服务、模块、控制器)将不起作用

于 2013-11-21T13:33:11.397 回答