Manually bootstrapping an application
When initializing an AngularJS application, very frequently you will allow the framework to do it transparently with the ng-app
directive. When attached to a DOM node, the application will be automatically initialized upon the DOMContentLoaded
event, or when the framework script is evaluated and the document.readyState === 'complete '
statement becomes true. The application parses the DOM for the ng-app
directive, which becomes the root element of the application. It will then begin initializing itself and compiling the application template. However, in some scenarios, you will want more control over when this initialization occurs, and AngularJS provides you with the ability to do this with angular.bootstrap()
. Some examples of this include the following:
Your application uses script loaders
You want to modify the template before AngularJS begins compilation
You want to use multiple AngularJS applications on the same page
Getting ready
When manually bootstrapping...