如何加载Gist代码而不会出现异步错误

时间:2014-12-31 15:32:04

标签: javascript ruby-on-rails angularjs asynchronous

我目前正在为自己的新博客上使用angular和rails,我被困住了。我使用ng-bind-html从后端注入代码。

现在我使用自己的指令修复它。

当我尝试从Github的Gist服务导入代码示例时,我当前收到以下错误:

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.

是什么原因以及如何解决这个问题?提前谢谢!

1 个答案:

答案 0 :(得分: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>