2013-11-22 20 views
0

因此,我正在嘗試製作一個簡單的小型pastebin,這對我來說主要是一項技術學習練習。我把一切都在前臺工作,除了highlight.js(庫任意選擇)嘗試將highlight.js集成到使用requirejs的角度應用程序

這裏是我的控制器

define([ 
    'highlight', 
    'angular', 
], function(hl) { 
    'use strict'; 

    return [  '$scope', '$location', '$routeParams', 'pastes', 
      function ($scope, $location, $routeParams, pastes) { 
        console.log(pastes); 
        var digest = $routeParams.digest; 
        if (pastes[digest]) { 
          $scope.code = hl.highlightAuto(pastes[digest]).value; 
          console.log($scope.code); 
        } 
        $scope.view = function(view) { 
          $location.path(view); 
        } 
        $scope.$apply(); 
      }]; 
}); 

和我的觀點

<pre ng-controller="Render"><code class="pre-scrollable"> 
{{code}} 
</code></pre> 
<button 
    type="button" 
    class="btn btn-primary pull-right" 
    ng-click="view('/')" 
>New Paste</button> 

要對得起這個代碼工作,問題是{{code}}似乎是消毒正在吐出的html,所以我需要找到另一種方式來做到這一點。嘗試了其他一些圖書館的咒語,但沒有任何進展。

+0

這裏的[我的代碼](https://bitbucket.org/xenoterracide/pastey-frontend/src/9e5ff8b761c9?at=master)的情況下,我已經離開了一個相關位 – xenoterracide

回答

1

如果問題是{{code}}被消毒,你試過ngBindHtmlUnsafe

<pre ng-controller="Render"> 
    <code class="pre-scrollable" ng-bind-html-unsafe="code"></code> 
</pre> 
+0

在這種情況下,在我將'ngSanitize'加載到我的角度模塊後,只會出現'ng-bind-html'。我之前不知道這件事,謝謝 – xenoterracide

相關問題