How to load Gist code without getting asynchronous error

I am currently working with angular and rails on a new blog for myself and I am stuck. I used ng-bind-html

to inject code from my backend.

I have now fixed it with my own directive.

I am currently getting the following error when I try to import the sample code from the Github Gist service:

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.

      

What is the reason and how to fix it? Thanks in advance!

+3


source to share


1 answer


The question is quite old, but I stumbled upon it while looking for an error. You can include https://github.com/blairvanderhoof/gist-embed/ in your project and then write a directive to apply the change:

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

    }
});

      



Then

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

      

0


source







All Articles