简体   繁体   English

角。 如何在指令内编译指令?

[英]Angular. how to compile directive inside directive?

I have 我有

<div id="content"><div>

I want to insert my directive. 我想插入我的指令。 I did 我做到了

html = $compile('<test></test>')($scope);
$("#content").html(html);

My directive: 我的指示:

app.directive("test", function ($compile, $route) {
    return {
        restrict: "E",
        templateUrl: "/Templates/test.html",
        controller: function ($scope, $location) {},
        controllerAs: "page"
    };
});

"/Templates/test.html": “/Templates/test.html”:

  ... some code ...
<category></category>

directives test and category upload some data from server. 指令测试和类别从服务器上传一些数据。 For some reasons category works, but test doesn't. 由于某些原因,类别有效,但测试没有。 Anybody knows why? 谁知道为什么? Thanks 谢谢

You could be required to recompile your directive. 您可能需要重新编译您的指令。 Add following code at the end of link function: 在链接功能的末尾添加以下代码:

$compile(element.contents())(scope);

Some useful info here: $complie 这里有一些有用的信息: $ complie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM