0

(this is done in es5 because I like working this way)

I want to use an Angular2 component to render a div with content followed by some generated Javascript. All the non-script view template gets rendered, but the ... never is rendered.

Following is an example code:

MyComponent =
ng.core.Component({
  selector : 'MY-COMPONENT',
  providers : [A defined provider],
})
.View({
        template : `
            <div id="{{contentID}}">
                {{content}}
            </div>
            <script type="text/javascript">
              alert('javascript code goes here');
            </script>
        `
})
.Class({
    constructor : [ng.core.ElementRef, function(el) {
        let retriever = new [working provider that retrieves content];
        this.contentID = el.nativeElement.getAttribute('ATTRIBUTE_WITH_ID');
        this.content = retriever.getContent(this.contentID);
  }]
});

Everything works as expected with the exception of the Javascript not being rendered. Any help?

  • [This question has bean answered here](http://stackoverflow.com/a/35570910/2530459) – KB_ May 08 '16 at 21:35

1 Answers1

0

Angular just strips the template of <script> tags. Use require() to load JS scripts from your components class.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567