Is it possible to run Javascript inside an Ember View Handlebars template? I want to run the Javascript when the template is added to the DOM.
window.App = Ember.Application.create()
App.TestView = Ember.View.create
tagName: 'div'
template: Ember.Handlebars.compile '<script>console.log("some javascript");</script><div>This is a view</div>'
App.TestView.append()
The
didInsertElementfunction on a view is invoked when it has been added to DOM, see documentation.You can then access the added view via
this.$(), see http://jsfiddle.net/NuaA6/Handlebars:
JavaScript: