In AngularJS, any inline javascript code that included in HTML templates doesn't work -


in angularjs, inline javascript code included in html templates doesn't work.

for example:

main.html file:

<div ng-include="'/templates/script.html'"></div> 

and script.html file:

<script type="text/javascript">     alert('yes'); </script> 

when open main page, expect alert message 'yes' nothing happens. think security restrictions in angularjs preventing inline scripts, couldn't find workaround that.

note: don't use jquery or other framework, angularjs 1.2.7.

jqlite not support script tags. jquery does, recommendation include jquery if need functionality.

from angular's igor minar in this discussion:

we looked supporting script tags in jqlite, needs done cross-browser support involves lot of black magic. reason decided going recommend users use jquery along angular in particular case. doesn't make sense rewrite 1 third of jquery working in jqlite.

here's related github issue jqlite should create elements in same way jquery igor sums up, before closing issue, this:

this craziness jqlite, not going it. instead going document if want have script elements in ng:include or ng:view templates, should use jquery.

demo plunker jquery


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -