In Angularjs, Any Inline JavaScript Code That Included in HTML Templates Doesn't Work

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

jQlite does not support script tags. jQuery does, so the recommendation is to include jQuery if you need this functionality.

From Angular's Igor Minar in this discussion:

we looked into supporting script tags in jqlite, but what needs to be
done to get a cross-browser support involves a lot of black magic. For
this reason we decided that for now we are just going to recommend
that users use jquery along with angular in this particular case. It
doesn't make sense for us to rewrite one third of jquery to get this
working in jqlite.

Here's the related github issue jqLite should create elements in same way as jQuery where Igor sums up, before closing the issue, with this:

This is too much craziness for jqlite, so we are not going to do it.
Instead we are going to document that if you want have script elements
in ng:include or ng:view templates, you should use jquery.

demo plunker with jquery

script not working with AngularJS

jQuery Library must stand before AngularJS library in declaration. This has solved my problem

Using inline code from database

In addition to the restructures mentioned by @31piy & @Wes H, it turns out the final step is to use $compile with a directive. Solution found here: Compiling dynamic HTML strings from database

How do I connect my AngularJS template HTML files to the main Javascript file loaded in the main page so that the ng-controller directives are found?

The problem was that I wasn't specifying the app.

Adding the attribute ng-app="WebApp" before the ng-controller attribute fixed the problem:

<form ng-app="WebApp" ng-controller="AgentLoginCtrl" name="userForm" style="width: 300px; background-color: white; border: 2px solid rgb(142, 169, 222); padding: 0px 5px 5px 5px">


Related Topics



Leave a reply



Submit