编译指令AngularJS内部指令 [英] compile directive inside directive AngularJS
问题描述
我试图使用 HighlightJS 上&LT指令; pre方式>由块href=\"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.
的下面是一个plunker重现问题:的结果
http://plnkr.co/edit/qZlMkjNZglV453caNphy?p=$p$pview一>
在这个例子:
<btf-markdown>
#Markdown directive
<pre hljs>
angular.forEach($scope.items,function(item){
console.log(item);
});
</pre>
</btf-markdown>
我期望&LT; pre&GT;
块的话,被 hljs
解析但没有。
I would expect the <pre>
block to get parsed by hljs
but does not.
我必须手动调用内部指令的编写?
Do I have to manually invoke the compilation of the inner directive?
推荐答案
在 btford.markdown
你的 element.html(HTML);
是覆盖 hljs
而不是:
var html = converter.makeHtml(element.text());
element.html(html);
我想你会preFER:
I think you'd prefer:
var html = converter.makeHtml(element.html());
element.html(html);
开关 element.text()
与 element.html()
所以你转换整个HTML元素(包括你的 hljs
- 这是不是在 element.text()
)。
So you're converting the whole html element (including your hljs
- which isn't in element.text()
).
下面是更新plunker: http://plnkr.co/edit/cURJ1QRfJRheOxTvYc1p? p = preVIEW
Here's the updated plunker: http://plnkr.co/edit/cURJ1QRfJRheOxTvYc1p?p=preview
这篇关于编译指令AngularJS内部指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!