如何在不出现异步错误的情况下加载 Gist 代码

How to load Gist code without getting async error

本文关键字:情况下 加载 Gist 代码 错误 异步      更新时间:2023-09-26

我目前正在为自己的新博客上使用角度和轨道,但我被困住了。我使用 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.

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

这个问题很老了,但我在搜索错误时偶然发现了它。您可以在项目中包括 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>