0

I have several blogs that are stored in my database. Some of them have javascript calculators inside the html like this one

<script type="text/javascript" src="http://www.financialsoccer.com/FinancialSoccer.js"></script>

I cannot get angular to parse the html and run the javascript.

So when it comes from the DB, it gets put into the scope value and looks something like this

$scope.article= '<h2> Financial Soccer</h2><script type="text/javascript" src="http://www.financialsoccer.com/FinancialSoccer.js"></script>'

I am already running it through $compile to compile any directives that may be in the blogs but the javascript wont execute.

.directive('dynamicElement', ['$compile', function ($compile) {
        return {
            restrict: 'E',
            scope: {
                article: "="
            },
            replace: true,
            link: function (scope, element, attrs) {
                var template = $compile(scope.article)(scope);
                element.replaceWith(template);
            }
        }
    }])

Is there a way to make this happen? Any help would be appreciated.

Thanks!

user973671
  • 1,620
  • 6
  • 27
  • 39
  • Might be related: http://stackoverflow.com/questions/21336350/in-angularjs-any-inline-javascript-code-that-included-in-html-templates-doesnt – SimpleJ Sep 27 '16 at 23:30
  • Yea, that doesn't really help. I already have the full version of jquery on the page. Thanks – user973671 Sep 27 '16 at 23:42
  • 1
    Of course it helps...it explains what you need to do. You can't run those tags through `$compile` and will need use jquery to insert the html. – charlietfl Sep 27 '16 at 23:45
  • I also need to run it through compile to attach directives in the html. – user973671 Sep 27 '16 at 23:54
  • then you need to figure out another approach to including your scripts such as `$.getScript()`. There are serious security concerns allowing scripts in content the way you are doing which is one main reason angular strips them – charlietfl Sep 28 '16 at 00:11

0 Answers0