2013-06-11 7 views
0

<markdown> 태그를 렌더링하라는 지시문에 의해 출력되는 <code> 태그를 강조 표시하는 지시문 작업.지시문 내부 지시문

<markdown> 지시문을 실행 한 후에 <code> 지시문이 절대 실행되지 않는 문제가 있습니다. 그러나 <code> 지시문은 <markdown> 지시문에서 출력되지 않는 코드 태그에서 실행됩니다.

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 서비스를 지침에 삽입하십시오. 그런 다음 element.html(html)을 설정 한 후 다음을 시도하십시오. $compile(element.contents())(scope);