Position inside html for angular <script> tag

I was given a project that integrates CodeIgniter with AngularJS. Since I do not have the real world exp. with angular, I go through aunts. I noticed sporadic problems with the html script tag that finds the angular.js file. Some of the tutorials have a script tag in the html tag, and some of them have a script tag at the bottom (before the closing tag). When pasted into the title tag, it works every time. But when placed at the bottom bottom, my application has problems. As if he did not recognize {{variable}} and did what he should. Should angular work in both places? I've always been taught that the only javascript link that goes to the head is Respond.js and modernizr.js. Everything else can be located at the bottom of the html page. I am using the latest stable version of angular.

Tony

+4
source share
2 answers

You must place it immediately before the closing body tag. Thus, JavaScript is executed after loading the html.

0
source

You can choose the method that you want, since it is SPA => loaded once, so there is no poor performance if in your head.

If you declare angular.jsat the bottom of the page, there is a good way to avoid this case for a missing interpolated variable:
you should use the directive ng-bindin your home template instead of indicating direct interpolation:

<div ng-bind="model.value"></div>

instead {{model.value}}

+3
source

All Articles