mercredi 29 juin 2016

EmberJS 1.13 Templating - script elements from htmlSafe string not executing JS

I have observed that, while writing JS in script tags into the template will run the script, inserting them into the template using a Handlebars expression will prevent it from running.

I have tried writing this into my component:

test: Ember.String.htmlSafe("<script>console.log('Hello World')</script>")

And in my template:

This will insert it into the DOM, but will not run the code. I thought it was because HTMLBars did not allow script tags in the template, but just writing

<script>console.log('Hello World')</script>

into the template itself will run the JS within.

Can somebody tell me if there is a way to achieve this, or provide an explanation as to why this happens? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire