Dan Kanze
Dan Kanze

Reputation: 18595

compile a directive passed from a scoped variable consumed by another directive AngularJS

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.

Here is an plunker recreating the problem:
http://plnkr.co/edit/9dFxvDpCx5Qn68Mk0uiv?p=preview

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>

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?

Upvotes: 2

Views: 209

Answers (1)

Ganaraj
Ganaraj

Reputation: 26841

Have a look at this fiddle . Basically, you just $compile any html that you want and append it to the new position.

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=preview

Upvotes: 2

Related Questions