Developer Guide: Initializing Angular: Manual Initialization

In the vast majority of cases you'll want to let Angular handle initialization automatically. If, however, you need to delay Angular from managing the page right after the DOMContentLoaded event fires, you'll need to control this initialization manually.

To initialize Angular -- after you've done your own special-purpose initialization -- just call the bootstrap() function with the HTML container node that you want Angular to manage. In automatic initialization you'd do this by adding the ngApp attribute to the same node. Now, you won't use ngApp anywhere in your document.

To show the contrast of manual vs. automatic initialization, this automatic method:

<!doctype html>
<html ng-app>
<head>
  <script src="http://code.angularjs.org/angular.js"></script>
...
</pre

is the same as this manual method:

<pre>
<!doctype html>
<html>
<head>
  <script src="http://code.angularjs.org/angular.js"></script>
  <script>
     angular.element(document).ready(function() {
       angular.bootstrap(document);
     });
  </script>
</head>
...

Related Topics

Related API

Compiler API