在动态加载AngularJS指令NG-包括不工作

问题描述:

我有一个自定义的指令,它增加了一些HTML。

I have a custom directive which adds some 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 NG-包括

This directive is loaded and used in a dynamically loaded html which is included via ng-include.

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

但简化版,它的工作。在连接 - 函数永远不会被调用。
如果我移动 dynamicscript.js 加载脚本从包含的HTML的 index.html的它的工作原理。

But it does't work. The linker-function is never called. It works if I move the dynamicscript.js script loading from the included html to the index.html.

这里是Plunkr

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

Just use RequireJS to load the controllers, directives, and so on.

使用特殊的插件,CSS和HTML文件可以装过。

Using special plugins, CSS and HTML files can be loaded too.

下面是本·纳德尔一个很好的例子:http://www.bennadel.com/blog/2554-Loading-AngularJS-Components-With-RequireJS-After-Application-Bootstrap.htm

Here is a great example from Ben Nadel: http://www.bennadel.com/blog/2554-Loading-AngularJS-Components-With-RequireJS-After-Application-Bootstrap.htm