2014-03-25 71 views
1

我有一個加載降價文件,並將其顯示爲HTML減價指令:如何在通過攤牌轉換的降價內使用角度指令?

// detail.html

<div markdown link="{{post.file"}}"></div> 

這工作得很好,甚至當我在降價文件的HTML標籤。但是我試圖在降價頁面上使用AngularUI Bootstrap指令,特別是Tabs。

這些選項卡具有特定於每個降價文件的內容,因此我無法在降價文件外放置指令。

回答

1

我想通了。您必須使用$compile服務。以下是完整的代碼示例:

angular.module('MyApp') 
    .directive('markdown', function($http, $compile) { 
    var converter = new Showdown.converter(); 
    return { 
     link: function(scope, element, attrs) { 
     attrs.$observe('file', function(file) { 
      if (file) { 
      $http.get('posts/' + file).success(function(response) { 
       var htmlText = converter.makeHtml(response); 
       element.html(htmlText); 

       $compile(element.contents())(scope); 

      }); 
      } 
     }); 
     } 
    } 
    });