簡體   English   中英

角。 如何在指令內編譯指令?

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

我有

<div id="content"><div>

我想插入我的指令。 我做到了

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

我的指示:

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

“/Templates/test.html”:

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

指令測試和類別從服務器上傳一些數據。 由於某些原因,類別有效,但測試沒有。 誰知道為什么? 謝謝

您可能需要重新編譯您的指令。 在鏈接功能的末尾添加以下代碼:

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

這里有一些有用的信息: $ complie

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM