2013-06-11 105 views
0

處理指令以突出顯示<code>標記,該標記正被指令輸出以呈現<markdown>標記。指令中的指令

問題是在運行<markdown>指令後<code>指令從未被命中。然而,<code>指令在代碼標籤上運行,這些代碼標籤不是從<markdown>指令輸出的。

降價指令

angular.module('App').directive "markdown", -> 
    converter = new Showdown.converter() 

    scope: true 
    restrict: 'E' 
    link: (scope, element, attrs) -> 
    if attrs.markdown 
     scope.$watch attrs.markdown, (newVal) -> 
     html = converter.makeHtml(newVal) 
     element.html(html) 
    else 
     redraw = -> 
     html = converter.makeHtml(element.text()) 
     element.html(html) 

     #### expecting the code directive to be trigger after this. 

     scope.$on "$includeContentLoaded", redraw 
     redraw() 

有什麼想法?

回答

1

AngularJS不知道從你的降價編譯任何東西。有兩種方法可以編譯這些東西。一種方法是使用transclusion,但我認爲這不適合你的用例。在你的情況下,你需要編譯你的降價變化。爲此,您使用Angular的$ compile服務。

首先,將$compile服務注入您的指令。然後設置element.html(html)後,試試這個:$compile(element.contents())(scope);