编译从另一个指令AngularJS消费的范围变量传递指令 [英] compile a directive passed from a scoped variable consumed by another directive AngularJS
问题描述
我试图使用<一个href=\"http://stackoverflow.com/questions/19959267/compile-directive-inside-directive-angularjs\">HighlightJS在指令&LT; pre&GT;通过的块=https://github.com/btford/angular-markdown-directive的rel = nofollow的>从范围变量降价的指令,这是一个从这个问题跟进。
I am trying to use a HighlightJS directive on <pre>
blocks rendered by a Markdown directive from a scoped variable, which is a follow up from this question.
的下面是一个plunker重现问题:的结果
http://plnkr.co/edit/9dFxvDpCx5Qn68Mk0uiv?p=$p$pview一>
的降价
指令编译 hljs
从 element.html()
---那就是:
The markdown
directive will compile hljs
from element.html()
--- that is:
<btf-markdown>
#Markdown directive
<pre hljs>
angular.forEach($scope.items,function(item){
console.log(item);
});
</pre>
</btf-markdown>
不过评估 hljs
从范围变量它属于通过:
However evaluating hljs
from a scoped variable it falls through:
<div btf-markdown="item">
</div>
我如何编译从另一个指令消耗的范围变量传递指令?
How do I compile a directive passed from a scoped variable consumed by another directive?
推荐答案
有一个看看这个小提琴。基本上,你只是 $编译
你想要的任何HTML和
追加到新的位置。
Have a look at this fiddle . Basically, you just $compile
any html that you want and append
it to the new position.
下面是一个更新普拉克与工作。如果你把在 pre
文本区域内与 hljs
它应该工作的罚款。
Here is an updated plunk with that working. If you put in a pre
inside the text area with hljs
it should work fine.
http://plnkr.co/edit/vZ2VlVCdSQWGBtgXLSAW?p=$p$ PVIEW
这篇关于编译从另一个指令AngularJS消费的范围变量传递指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!