编译指令AngularJS内部指令 [英] compile directive inside directive AngularJS

查看:126
本文介绍了编译指令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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆