2016-06-11 32 views
0

我有這個問題,因爲某些奇怪的原因,我的代碼無法正常渲染,並且生病讓我看看我的代碼。因此,這裏是我的代碼從控制器(AngularJS):MarkedJS中的渲染

$scope.$watch('creatorValue', function(current, original) { 
      var htmlVal = document.getElementById('creatorValue').innerHTML; 
      console.log(original); 
      htmlVal = marked(original); 
}); 

這裏是一個最小的HTML:

<div class="topic-sentence"> 
     <p class="topic-text" id="creatorValue">{{creatorValue}}</p> 
</div> 

好吧,你可以看到我記錄的原始值,並提出了正確的結果: enter image description here

好吧,它記錄正​​確的東西....然後它必須顯示正確的顯示權利? enter image description here

不,就像你在上面看到的那樣,所有的代碼都在一行中,並且沒有任何「標記」。如果你們想看更多的代碼,請在下面的評論中告訴我們。非常感謝幫助。

回答

1

在這裏,你沒有把標記的內容放回到DOM。這應該工作,請嘗試。

$scope.$watch('creatorValue', function(current, original) {   
    document.getElementById('creatorValue').innerHTML = marked(original); 
}); 
+0

是的,當我問了這個問題,然後我知道了之後,Yup嘗試了$ scope.creatorValue和ng-bind-html rigth。你的方式與我的方式不同,但仍然實現相同的目標。感謝您的幫助,確定這將有助於許多用戶。 – amanuel2