2014-12-31 40 views
3

我目前正在爲自己的新博客上使用angular和rails,並且卡住了。我用ng-bind-html來注入我後端的代碼。如何加載Gist代碼而不會出現異步錯誤

現在我用自己的指令修復它。

我目前得到當我試圖從GitHub的主旨服務導入代碼示例以下錯誤:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened. 

的原因是什麼,如何解決這一問題?提前致謝!

+0

我們展示你的代碼。 – SLaks

+0

看起來很明顯,你不能在頁面加載後使用'document.write',否則它會消除頁面中的所有內容。 – charlietfl

+1

需要更多信息/代碼示例/庫用於幫助你。我遇到了類似的問題。我使用[gist-embed](https://github.com/blairvanderhoof/gist-embed)庫。當使用ng-bind-html時,我必須用'''gist()''重新編譯綁定的html。也可以看看https://github.com/pasupulaphani/angular-gist-embed,它可以幫助你。 – phani

回答

0

這個問題很古老,但我在搜索錯誤時偶然發現了它。您可以在您的項目https://github.com/blairvanderhoof/gist-embed/然後寫一個指令,以應用更改:

yourApp.directive('gistDirective', function() { 
    return function(scope, element, attrs) { 
     scope.$watch('someAngularVariable', function(){ 
      angular.element('[data-gist-id]').gist(); 
     }); 

    } 
}); 

然後

<section gist-directive> 
       <article> 
        <div ng-bind-html="trustHtml(someAngularVariable.body)"></div> 
       </article> 
    </section> 
相關問題